[code]
//
// Copyright (c) 2010, cheol-dong choi, <http://www.sarangnamu.net>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
package com.example.hellojni;
/**
* ocp 에서는 token 을 0x1E 를 사용하기 때문에 byte를 구분으로 data를
* 나뉠 수 있는 Tokenizer 가 필요해서 생성.
*
*/
public class ByteTokenizer {
/*
* constructor
*/
public ByteTokenizer(String buffer, int token) {
_buffer = buffer;
_token = token;
}
/*
* public methods
*/
/**
* token 정보를 기준으로 데이터를 자른다.
* @return true or false
*/
public boolean hasMoreTokens() {
/*
* indexOf 에서 search 를 하지 못한 경우 -1 을 return 하게 된다.
*/
int pos =_buffer.indexOf(_token);
if (pos > 0) {
_tokenValue = _buffer.substring(0, pos);
_buffer = _buffer.substring(pos + 1);
return true;
} else {
if (_buffer.length() > 0) {
_tokenValue = _buffer;
_buffer = "";
return true;
}
}
return false;
}
/**
* 현재 위치에 string 을 return 한다.
* @return string data
*/
public String nextToken() {
return _tokenValue;
}
/*
* attributes
*/
private int _token;
private String _buffer;
private String _tokenValue;
}
[/code]
//
// Copyright (c) 2010, cheol-dong choi, <http://www.sarangnamu.net>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
package com.example.hellojni;
/**
* ocp 에서는 token 을 0x1E 를 사용하기 때문에 byte를 구분으로 data를
* 나뉠 수 있는 Tokenizer 가 필요해서 생성.
*
*/
public class ByteTokenizer {
/*
* constructor
*/
public ByteTokenizer(String buffer, int token) {
_buffer = buffer;
_token = token;
}
/*
* public methods
*/
/**
* token 정보를 기준으로 데이터를 자른다.
* @return true or false
*/
public boolean hasMoreTokens() {
/*
* indexOf 에서 search 를 하지 못한 경우 -1 을 return 하게 된다.
*/
int pos =_buffer.indexOf(_token);
if (pos > 0) {
_tokenValue = _buffer.substring(0, pos);
_buffer = _buffer.substring(pos + 1);
return true;
} else {
if (_buffer.length() > 0) {
_tokenValue = _buffer;
_buffer = "";
return true;
}
}
return false;
}
/**
* 현재 위치에 string 을 return 한다.
* @return string data
*/
public String nextToken() {
return _tokenValue;
}
/*
* attributes
*/
private int _token;
private String _buffer;
private String _tokenValue;
}
[/code]
'Android' 카테고리의 다른 글
dialog window (0) | 2013.10.08 |
---|---|
native log (0) | 2013.10.08 |
byte to string (0) | 2013.10.08 |
android thread (0) | 2013.10.08 |
the applications move to sdcard (0) | 2013.10.08 |