2020. 12. 1. 12:02

Big Sur

Big Sur로 업데이트 후에 기존에 사용하던 eclipse를 사용할 수 없게 되어 새로운 버전으로 업그레이드 해야 하고 여전히 개발을 위해 언어를 영어로 변경했다가 한국어로 재변경을 해야만 jdbc연결이 제대로 되고 아직까지도 java application 디스플레이가 뭔가 불안해 보이지만 그래도 깔끔한 UI는 마음에 드네요.

Posted by 모바일헌터
2019. 10. 6. 11:47

String > byte[] > 압축 > byte[] ==[전송]==> byte[] > 압축 해제 > byte[] > String

 

String이 네트워크에서 전송이 된다면 1byte 문자세트를 이용하는 것이 바람직하다.

String > byte[] > 압축 > byte[] > String ==[전송]==> String >  byte[] > 압축 해제 > byte[] > String문제는

new String(baos.toByteArray(), "ISO-8859-1") String ==[전송]==>String :  input.getBytes("ISO-8859-1")

 

입력된 String은 한글이 포함된 UTF-8이라고 가정하여 압축 해제 후에 한글이 깨지지 않게  UTF-8 잊지 마세요....

 

    public static String compress(String input) throws Exception {
        String result = null;
        if (input != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            GZIPOutputStream gzipos = new GZIPOutputStream(baos);
            gzipos.write(input.getBytes());
            gzipos.close();
            result = new String(baos.toByteArray(), "ISO-8859-1");
            baos.close();
        }
        return result;
    }


    public static String decompress(String input) throws IOException {

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input.getBytes("ISO-8859-1"));
        GZIPInputStream gzipInputStream = new GZIPInputStream(byteArrayInputStream);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(gzipInputStream);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
         
        byte[] buffer = new byte[1024];
         
        int length;
        while((length = bufferedInputStream.read(buffer,0,1024)) > 0) {
            byteArrayOutputStream.write(buffer, 0, length);
        }
         
        bufferedInputStream.close();
        gzipInputStream.close();
        byteArrayInputStream.close();
        byteArrayOutputStream.close();
         
        return byteArrayOutputStream.toString("UTF-8");  
    }

'개발 거들기' 카테고리의 다른 글

해당월의 마지막 날짜 가져오기  (0) 2017.02.22
소스를 블로그에 올릴 때  (0) 2016.05.12
ATOM에서 TODO관리하기  (0) 2015.12.21
git 로컬 저장소 생성(.git 폴더)  (0) 2015.01.14
git 수정사항 확인  (0) 2015.01.14
Posted by 모바일헌터