예전엔 byte가 깨질거 고려해서 hex string으로 변환해서 사용했었는데.. 모바일 쪽에서는 base64를 사용하는 곳이 있는듯 싶다. 뭐 사용하기 나름이니까.. 쩌ㅃ~

Base64로 인코딩된 문자열을 byte array로 디코딩 해준다.
public static byte[] base64Decode(String source) {
       byte[] buffer = null;
   
       BASE64Decoder base64Decoder     = new BASE64Decoder();
       ByteArrayInputStream  in     = new ByteArrayInputStream(source.getBytes());
       ByteArrayOutputStream out     = new ByteArrayOutputStream();

       try {
           base64Decoder.decodeBuffer(in, out);
       } catch (Exception e) {
           e.printStackTrace();
       }
       buffer = out.toByteArray();
       return buffer;
}

'java > util' 카테고리의 다른 글

[java] - byte array to image  (0) 2010.06.30
[java] - 소수점 자르기 (duble type)  (0) 2010.06.30
[java] - 타입 변환  (0) 2010.06.30
[java] - 외부 프로그램 실행하기..  (0) 2010.06.29
[java] - byte array to int  (0) 2010.06.29
Posted by 짱가쟁이
2010. 6. 30. 09:33
출처

int to String
String str = Integer.toString(i);
String str = "" + i;


String to int
int i = Integer.parseInt(str);

int i = Integer.valueOf(str).intValue();


double to String
String str = Double.toString(d);


long to String
String str = Long.toString(l);


float to String
String str = Float.toString(f);


String to double
double d = Double.valueOf(str).doubleValue();


String to long
long l = Long.valueOf(str).longValue();

long l = Long.parseLong(str);


String to float
float f = Float.valueOf(str).floatValue();


decimal to binary
String binstr = Integer.toBinaryString(i);


decimal to hexadecimal
String hexstr = Integer.toString(i, 16);

String hexstr = Integer.toHexString(i);

Integer.toHexString( 0x10000 | i).substring(1).toUpperCase());


hexadecimal(String) to int
int i = Integer.valueOf("B8DA3", 16).intValue();

int i = Integer.parseInt("B8DA3", 16);


ASCII Code to String
String char = new Character((char)i).toString();


Integer to ASCII Code
int i = (int) c;


Integer to boolean
boolean b = (i != 0);


boolean to Integer
int i = (b)? 1 : 0;


'java > util' 카테고리의 다른 글

[java] - 소수점 자르기 (duble type)  (0) 2010.06.30
[java] - base54 String decode  (0) 2010.06.30
[java] - 외부 프로그램 실행하기..  (0) 2010.06.29
[java] - byte array to int  (0) 2010.06.29
[java] - int to byte array  (0) 2010.06.29
Posted by 짱가쟁이
/**
  *
  * @param command
  *     ex> "java -jar jface/util/tool/trang.jar D:\\runtest\\tableconfig.xml D:\\runtest\\TableConfig.xsd"
  */
 public void launcher(String command) {
 
  try {
   String s;
   String error = "";
  
   Process process = new ProcessBuilder("cmd", "/c", command).start();
  
   // 외부 프로그램 출력 읽기
      BufferedReader stdOut   =
       new BufferedReader(new InputStreamReader(process.getInputStream()));
      BufferedReader stdError =
       new BufferedReader(new InputStreamReader(process.getErrorStream()));
 
      // "표준 출력"과 "표준 에러 출력"을 출력
      while ((s =   stdOut.readLine()) != null) {
       System.out.print(s);
      }
      while ((s = stdError.readLine()) != null) {
       error = error + s;      
      }
 
      if(process.exitValue() == 0) {
       MessageDialog.openInformation(parent.getParent().getShell(),
         "XSD generate", parent.getXsdLocationText().getText() + " 를 생성했습니다.");
      } else {
       MessageDialog.openInformation(parent.getParent().getShell(),
         "XSD generate", error + "\n\n" + parent.getXsdLocationText().getText() + " 생성에 실패했습니다.");
      }

  } catch(Exception e) {
   e.printStackTrace();
  }
 }

'java > util' 카테고리의 다른 글

[java] - base54 String decode  (0) 2010.06.30
[java] - 타입 변환  (0) 2010.06.30
[java] - byte array to int  (0) 2010.06.29
[java] - int to byte array  (0) 2010.06.29
[java] - Big Endian to Little Endian  (0) 2010.06.29
Posted by 짱가쟁이
public static int byteToInt(byte[] src) {

        int newValue = 0;

        newValue |= (((int)src[0])<<24)&0xFF000000;
        newValue |= (((int)src[1])<<16)&0xFF0000;
        newValue |= (((int)src[2])<<8)&0xFF00;
        newValue |= (((int)src[3]))&0xFF;

        DebugPrint.writeDebug("aaaa : " + newValue);
      
        return newValue;
}

'java > util' 카테고리의 다른 글

[java] - 타입 변환  (0) 2010.06.30
[java] - 외부 프로그램 실행하기..  (0) 2010.06.29
[java] - int to byte array  (0) 2010.06.29
[java] - Big Endian to Little Endian  (0) 2010.06.29
[java] - Little Endian to Big Endian  (0) 2010.06.29
Posted by 짱가쟁이
public static byte[] intTobyte(int value) {
        byte[] bytes=new byte[4];
        bytes[0]=(byte)((value&0xFF000000)>>24);
        bytes[1]=(byte)((value&0x00FF0000)>>16);
        bytes[2]=(byte)((value&0x0000FF00)>>8);
        bytes[3]=(byte) (value&0x000000FF);


        return bytes;

}

'java > util' 카테고리의 다른 글

[java] - 외부 프로그램 실행하기..  (0) 2010.06.29
[java] - byte array to int  (0) 2010.06.29
[java] - Big Endian to Little Endian  (0) 2010.06.29
[java] - Little Endian to Big Endian  (0) 2010.06.29
[java] - float to byte array  (1) 2010.06.29
Posted by 짱가쟁이
public static int swapLittleEndian(byte[] bytes) {
     
        int newValue = 0;
        newValue |= (((int)bytes[3])<<24)&0xFF000000;
        newValue |= (((int)bytes[2])<<16)&0xFF0000;
        newValue |= (((int)bytes[1])<<8)&0xFF00;
        newValue |= (((int)bytes[0]))&0xFF;


        return newValue;

}

'java > util' 카테고리의 다른 글

[java] - byte array to int  (0) 2010.06.29
[java] - int to byte array  (0) 2010.06.29
[java] - Little Endian to Big Endian  (0) 2010.06.29
[java] - float to byte array  (1) 2010.06.29
[java] - byte array to float  (0) 2010.06.29
Posted by 짱가쟁이
public static int swapBigEndian(String args) {

        int value=Integer.parseInt(args);

        // all java integer is BIG-ENDIAN(network byte-order)
        byte[] bytes=new byte[4];
        bytes[3]=(byte)((value&0xFF000000)>>24);
        bytes[2]=(byte)((value&0x00FF0000)>>16);
        bytes[1]=(byte)((value&0x0000FF00)>>8);
        bytes[0]=(byte) (value&0x000000FF);


        int newValue = 0;
        newValue |= (((int)bytes[0])<<24)&0xFF000000;
        newValue |= (((int)bytes[1])<<16)&0xFF0000;
        newValue |= (((int)bytes[2])<<8)&0xFF00;
        newValue |= (((int)bytes[3]))&0xFF;

        return newValue;
}

'java > util' 카테고리의 다른 글

[java] - int to byte array  (0) 2010.06.29
[java] - Big Endian to Little Endian  (0) 2010.06.29
[java] - float to byte array  (1) 2010.06.29
[java] - byte array to float  (0) 2010.06.29
[java] - byte array to short  (0) 2010.06.29
Posted by 짱가쟁이
public static byte[] float2bytes(float value) {
      
        byte[] array = new byte[4];
      
        int intBits=Float.floatToIntBits(value);
      
        array[0]=(byte)((intBits&0x000000ff)>>0);
        array[1]=(byte)((intBits&0x0000ff00)>>8);
        array[2]=(byte)((intBits&0x00ff0000)>>16);
        array[3]=(byte)((intBits&0xff000000)>>24);
      
        return array;
}

Posted by 짱가쟁이
public static float arr2float (byte[] arr, int start) {

            int i = 0;
            int len = 4;
            int cnt = 0;
            byte[] tmp = new byte[len];

            for (i = start; i < (start + len); i++) {
                  tmp[cnt] = arr[i];
                  cnt++;
            }

            int accum = 0;
            i = 0;
            for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) {
                  accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
                  i++;
            }
            return Float.intBitsToFloat(accum);
}    

Posted by 짱가쟁이
public static int byteToShort(byte[] bytes) {
     
            int newValue = 0;
            newValue |= (((int)bytes[0])<<8)&0xFF00;
            newValue |= (((int)bytes[1]))&0xFF;

            return newValue;
}

Posted by 짱가쟁이
이전버튼 1 2 3 4 이전버튼