Java Parser (SAX vs DOM)에 대해 정리한다.
sax paser는 dom parser 대비 메모리 절약의 장점이 있으나, Random access 미지원 (Top down 형식으로 검색.)
- dom parser의 경우 xml 1byte 당 10byte 소모
- dom parser : xml parsing tree 유지
https://www.tutorialspoint.com/java_xml/java_sax_parser.htm
https://www.tutorialspoint.com/java_xml/java_dom_parse_document.htm
#java #sax_parser #domparser
2019년 3월 25일 월요일
COS - Java Card Smart Card Operation System
COS - Java Card Smart Card Operation System
https://stove99.tistory.com/96
https://stove99.tistory.com/96
Java 형변환 예제
Google+ 서비스 종료로 인해 과거의 기록들을 이곳으로 옮겨둔다.
Java 형변환에 대한 예.
String to Int
1. Integer.parseInt(string);
2. Integer.valueOf(string);
Integer.parseInt()
int Num = Integer.parseInt(Str);
--------------------------------------------------------------------------------------------------
Int to String
1. String.valueOf(number)
2. Integer.toString(number)
3. number + ""
-> String.valueOf(number) 와 Interger.toString(number) 는 동일.
-> number+"" 는 다른것에 비해 속도가 느리다.
--------------------------------------------------------------------------------------------------
Object to Byte Array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(yourObject);
byte[] yourBytes = bos.toByteArray();
--------------------------------------------------------------------------------------------------
Byte Array to Object
ByteArrayIntputSream bis = new ByteArrayInputStream(yourBytes);
ObjectInput in = new ObjectInputStream(bis);
Object o = in.readObject();
--------------------------------------------------------------------------------------------------
Int to Byte Array
public static byte[] i2b_le(int myInteger){
return ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(myInteger).array();
}
public static byte[] i2b_be(int myInteger){
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(myInteger).array();
}
--------------------------------------------------------------------------------------------------
Byte Array to Int
public static int b2i_le(byte [] byteBarray){
return ByteBuffer.wrap(byteBarray).order(ByteOrder.LITTLE_ENDIAN).getInt();
}
public static int b2i_be(byte [] byteBarray){
return ByteBuffer.wrap(byteBarray).order(ByteOrder.BIG_ENDIAN).getInt();
}
--------------------------------------------------------------------------------------------------
String to Byte Array
byte[] b = string.getBytes();
byte[] b = string.getBytes(Charset.forName("UTF-8"));
--------------------------------------------------------------------------------------------------
Byte Array to String
byte [] t_sub3= getbytes(rcvData,8,rcvData.length-8);
String str = new String(t_sub3,0,t_sub3.length);
* t_sub3은 배열 이름, 0~t_sub3.length는 offset 이다.
--------------------------------------------------------------------------------------------------
Byte Array 부분 복사하기
public static void arraycopy(Object src,
int srcPos,
Object dest,
int destPos,
int length)
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.
A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest.
The number of components copied is equal to the length argument.
The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination array.
--------------------------------------------------------------------------------------------------
ArrayList 사용 method
myList.size() : 객체의 size 확인
myList.indexOf(d) : 객체의 index 확인
myList.contains(d) : 객체 존재여부 확인
myList.isEmpty() : ArrayList가 비어있는지 확인
myList.remove(d) : ArrayList에 있는 객체 제거
Java 형변환에 대한 예.
String to Int
1. Integer.parseInt(string);
2. Integer.valueOf(string);
Integer.parseInt()
int Num = Integer.parseInt(Str);
--------------------------------------------------------------------------------------------------
Int to String
1. String.valueOf(number)
2. Integer.toString(number)
3. number + ""
-> String.valueOf(number) 와 Interger.toString(number) 는 동일.
-> number+"" 는 다른것에 비해 속도가 느리다.
--------------------------------------------------------------------------------------------------
Object to Byte Array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(yourObject);
byte[] yourBytes = bos.toByteArray();
--------------------------------------------------------------------------------------------------
Byte Array to Object
ByteArrayIntputSream bis = new ByteArrayInputStream(yourBytes);
ObjectInput in = new ObjectInputStream(bis);
Object o = in.readObject();
--------------------------------------------------------------------------------------------------
Int to Byte Array
public static byte[] i2b_le(int myInteger){
return ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(myInteger).array();
}
public static byte[] i2b_be(int myInteger){
return ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(myInteger).array();
}
--------------------------------------------------------------------------------------------------
Byte Array to Int
public static int b2i_le(byte [] byteBarray){
return ByteBuffer.wrap(byteBarray).order(ByteOrder.LITTLE_ENDIAN).getInt();
}
public static int b2i_be(byte [] byteBarray){
return ByteBuffer.wrap(byteBarray).order(ByteOrder.BIG_ENDIAN).getInt();
}
--------------------------------------------------------------------------------------------------
String to Byte Array
byte[] b = string.getBytes();
byte[] b = string.getBytes(Charset.forName("UTF-8"));
--------------------------------------------------------------------------------------------------
Byte Array to String
byte [] t_sub3= getbytes(rcvData,8,rcvData.length-8);
String str = new String(t_sub3,0,t_sub3.length);
* t_sub3은 배열 이름, 0~t_sub3.length는 offset 이다.
--------------------------------------------------------------------------------------------------
Byte Array 부분 복사하기
public static void arraycopy(Object src,
int srcPos,
Object dest,
int destPos,
int length)
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.
A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest.
The number of components copied is equal to the length argument.
The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination array.
--------------------------------------------------------------------------------------------------
ArrayList 사용 method
myList.size() : 객체의 size 확인
myList.indexOf(d) : 객체의 index 확인
myList.contains(d) : 객체 존재여부 확인
myList.isEmpty() : ArrayList가 비어있는지 확인
myList.remove(d) : ArrayList에 있는 객체 제거
2019년 1월 10일 목요일
[Android] How to make standalone toolchain
Android 7.x 기준으로 NDK standalone toolchain을 생성하는 방법을 정리한다.
1. Android NDK 다운로드 후 압축
: 문서를 작성중인 현재 stable 버전은 r16b이다.
- https://developer.android.com/ndk/downloads/
2. standalone toolchain 생성
$ cd android-ndk
$ make-standalone-toolchain.sh --verbose --toolchain=arm-linux-androideabi-4.9 --package-dir=/home/sisbsoma/toolchain --platform=android-26 --arch=arm
HOST_OS=linux
HOST_EXE=
HOST_ARCH=x86_64
HOST_TAG=linux-x86_64
HOST_NUM_CPUS=8
BUILD_NUM_CPUS=16
## COMMAND: python /opt/android-sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --api 26 --stl gnustl --package-dir=/home/sisbsoma/toolchain
정상적으로 생성된 경우 아래와 같은 로그가 출력된다.
Package installed to /home/sisbsoma/toolchain.
생성된 이미지는 tar.bz2 형태로 압축되어 있다.
$ cd /home/sisbsoma/toolchain && ls
arm-linux-androideabi.tar.bz2
2018년 11월 6일 화요일
[Linux] Shell script for git pull - username & password 자동입력
Linux 환경에서 git pull 명령어 수행시 username & password를 script로 처리하기 위한 작업을 정리한다.
System : Ubuntu 14.04 LTS
==================================================================
script 수행을 위해서는 expect 가 설치되어 있어야 한다.
$ sudo apt-get install expect
expect 명령어는 아래와 같이 정의되어 있다. (자세한 내용은 링크 참조)
==================================================================
$ git-pull -d $HOME/work/project1 -u sisbsoma -p 1234
------------------------------------------------------------------------------------------------
file path : $HOME/bin/git-pull
#!/bin/bash
System : Ubuntu 14.04 LTS
==================================================================
script 수행을 위해서는 expect 가 설치되어 있어야 한다.
$ sudo apt-get install expect
expect 명령어는 아래와 같이 정의되어 있다. (자세한 내용은 링크 참조)
- Expect is a program that "talks" to other interactive programs according to a script.
- expect 기본 명령
- spawn : 명령어를 실행한다.
- expect “문자열” : “문자열"을 만나면
- send “문자열\r” : "문자열"을 전송한다.
- interact : expect를 끝내고 사용자에게 제어권을 넘긴다.
- expect eof : expect 종료
==================================================================
[ Script Sample ]
사용자 옵션이 없을 경우, script에 정의된 default parameter를 기준으로 동작하도록 정의한다.------------------------------------------------------------------------------------------------
[ Sample code]
file path : $HOME/bin/git-pull
#!/bin/bash
# Username &
Password
USERNAME=USER_NAME ## set user.name for git repository
PASSWD=PASSWORD ## set password for git repository
# Default Working
directory
WORKDIR=$HOME/work ## set default working directory
# Help function
usage() {
echo "usage :
$0 [OPTIONS]"
echo " -h : Display Usage"
echo " -d : Working Directory"
echo " -u : Username"
echo " -p : Password"
exit 0
}
# Git pull
func_gitpull() {
cd $WORKDIR
expect <<EOF
spawn git pull
expect
"Username"
send $USERNAME\r
expect
"Password"
send $PASSWD\r
expect eof
EOF
}
# Update params
while getopts
"h:d:u:p:" opt
do
case $opt in
d) WORKDIR=$OPTARG
;;
u) USERNAME=$OPTARG
;;
p) PASSWD=$OPTARG
;;
h) usage ;;
?) usage ;;
esac
done
func_gitpull
------------------------------------------------------------------------------------------------
2018년 6월 11일 월요일
[Android] Jack Server : How to support Multi User environment
Android Build
System - Jack Server : How to support Multi User environment
#android_jack-server_multi-user
OS : Android 7.1
OS : Android 7.1
Single Build machine & Multi user 환경에서의 Android platform build 시 자동으로 사용자별(user id를 참조하여) jack-server를 구동하는 방법에 대해 기록한다.
- https://github.com/whitemuse/aosp-jack-server
Jack
limitations (https://source.android.com/setup/build/jack)
By default, the Jack server is mono-user and can be only one user on
a computer. To support additional users, select different port number for each
user and adjust SERVER_NB_COMPILE accordingly. You can also disable the Jack
server by setting SERVER=false in $HOME/.jack
웹 검색을 통해 사용자 별 Jack Server의 포트설정을 다르게 사용하는 것으로 해결이 가능함을 확인 할 수 있다. 다만, jack server 동작을 위한 설정파일($HOME/.jack-server/config.properties, $HOME/.jack-settings) 을 수동으로 편집해야 하는 불편함이 따른다. Build 시 자동으로 설정되도록 아래와 같이 수정한다.
-----------------------------------------------------------------------------------------
Runtime port 설정변경 & New jack server start
1. android/prebuilts/sdk/tools/jack
33 #####################################################
34 # TEAM - SISBSOMA
35 PORT_OFFSET=`id -u`
36 SERVER_PORT_SERVICE=`expr 8076 + ${PORT_OFFSET}`
37 SERVER_PORT_ADMIN=`expr 8077 + ${PORT_OFFSET}`
38 #####################################################
2. android/prebuilts/sdk/tools/jack-admin
45
#####################################################
46 # TEAM - SISBSOMA
47 PORT_OFFSET=`id -u`
48 SERVER_PORT_SERVICE_DEFAULT=8076
49
SERVER_PORT_ADMIN_DEFAULT=8077
50
51 SERVER_PORT_SERVICE=`expr
8076 + ${PORT_OFFSET}`
52 SERVER_PORT_ADMIN=`expr
8077 + ${PORT_OFFSET}`
53
######################################################
54
55 #####################################################
56 # TEAM - SISBSOMA
57 updatePortNum() {
58 echo "Update Port Number - Jack
Sever"
59 T_P=`grep SERVER_PORT_SERVICE
~/.jack-settings | cut -d'=' -f2`
60 if [ "$T_P" -ne
"$SERVER_PORT_SERVICE" ]; then
61 if [ -f "$CLIENT_SETTING" ];
then
62 sed -i
's/SERVER_PORT_SERVICE.*/SERVER_PORT_SERVICE='$SERVER_PORT_SERVICE'/g'
$CLIENT_SETTING
63 sed -i
's/SERVER_PORT_ADMIN.*/SERVER_PORT_ADMIN='$SERVER_PORT_ADMIN'/g'
$CLIENT_SETTING
64 fi
65 fi
66 if [
-d "$JACK_HOME" ]; then
67 sed -i
's/jack.server.service.port.*/jack.server.service.port='$SERVER_PORT_SERVICE'/g'
"$JACK_HOME/config.properties"
68 sed -i
's/jack.server.admin.port.*/jack.server.admin.port='$SERVER_PORT_ADMIN'/g'
"$JACK_HOME/config.properties"
69 fi
70 }
71
#####################################################
216 waitServerStarted () {
217 DONE=1
218 let DATE_TIMEOUT=$(date
+%s)+$JACK_CONNECTION_TIMEOUT
219 while [
"$DONE" -ne 0 ]; do
220 HTTP_CODE=$(curl -f
$JACK_EXTRA_CURL_OPTIONS \
221 --cert
"${JACK_HOME}/client.pem" \
222 --cacert
"${JACK_HOME}/server.pem" \
223 --output
/dev/null \
224 --no-buffer
--write-out '%{http_code}' --silent --connect-timeout $JACK_CONNECTION_TIMEOUT
\
225 -X GET \
226 -H "Accept:
text/plain$CHARSET_ARGUMENT" \
227 --noproxy
${SERVER_HOST} \
228
https://${SERVER_HOST}:$SERVER_PORT_ADMIN/server \
229 )
230 CURL_CODE=$?
231 if [ $CURL_CODE -eq 7
] || [ $CURL_CODE -eq 35 ] || [ $CURL_CODE -eq 58 ] || [ $CURL_CODE -eq 60 ] ||
[ $CURL_CODE -eq 77 ]; then
232 if [ $(date +%s) -ge
$DATE_TIMEOUT ]; then
233 echo "Jack
server failed to (re)start, try 'jack-diagnose' or see Jack server log"
>&2
234 abort
235 else
236
#####################################################
237 # TEAM - SISBSOMA
238 if [
"$CURL_CODE" -eq 7 ]; then
239 if [ -f
"$JACK_HOME/config.properties" ]; then
240 JSSP=`grep
"jack.server.service.port" "$JACK_HOME/config.properties" |
cut -d'=' -f2`
241 if [
"$JSSP" -ne "$SERVER_PORT_SERVICE" ]; then
242 echo
"@@ (New) Jack Server start~!!"
243
updatePortNum
244
funcStartServer
245
funcStopServer $JSSP
246 fi
247 fi
248 fi
249
#####################################################
250 sleep 1
251 fi
252 else
253 # A connection was
opened, no need to know if it went well
254 DONE=0;
255 fi
256 done
257 }
278 funcStopServer() {
279 echo "Stopping
background server : $1"
280 HTTP_CODE=$(curl -f
$JACK_EXTRA_CURL_OPTIONS \
281 --cert
"${JACK_HOME}/client.pem" \
282 --cacert
"${JACK_HOME}/server.pem" \
283 --output
/dev/null \
284 --no-buffer
--write-out '%{http_code}' --silent --connect-timeout $JACK_CONNECTION_TIMEOUT
\
285 -X POST \
286 --noproxy
${SERVER_HOST} \
287
https://${SERVER_HOST}:$1/server/stop \
288 )
289
290 handleHttpErrors $?
$HTTP_CODE
291 }
292
293 funcStartServer() {
294
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1
-Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -cp $LAUNCHER_JAR
$LAUNCHER_NAME"
295 echo "Launching
Jack server" $JACK_SERVER_COMMAND
296 (
297 trap ""
SIGHUP
298 for i in $(seq 3
255); do
299 eval exec
"$i"'>&-'
300 done
301 cd
"$JACK_HOME"
302 umask $BASE_UMASK
303 exec
$JACK_SERVER_COMMAND
304 abort
305 )
>"$JACK_OUT_ERR" 2>&1 &
306 }
[Android] porting - memtester
How to Install memtester on Android system
Memory test를 위한 tool 적용ref : https://github.com/royzhao/memtester4Android
version : 4.3.0 (32-bit)
=====================================
usage:
cd android/
source ./build/envsetup.sh
lunch xx
cd android/external/
git clone https://github.com/royzhao/memtester4Android.git
cd memtester4Android
mm
=====================================
Android.mk
1 LOCAL_PATH := $(call my-dir)
2 include $(CLEAR_VARS)
3
4 LOCAL_MODULE_TAGS := debug
5
6 LOCAL_SRC_FILES:= \
7 memtester.c tests.c
8 LOCAL_MODULE:= memtester
9 LOCAL_MODULE_FILENAME:=memtester
10 LOCAL_C_INCLUDES:=$(LOCAL_PATH)
11 #LOCAL_C_INCLUDES :=
12 #LOCAL_STATIC_LIBRARIES :=
13 #LOCAL_SHARED_LIBRARIES :=
14 include $(BUILD_EXECUTABLE)
15
피드 구독하기:
덧글 (Atom)