받은 문자열을 디코딩하려고합니다. 여기 deflater를 사용하여 압축되었습니다 : https://github.com/dankogai/js-deflate 그리고 base64로 인코딩되었습니다.Java.util.zip.Inflater를 사용하여 문자열 압축 풀기
그러나 자바 인플레이터를 사용할 때 알 수없는 압축 방법 인 다음과 같은 오류 메시지가 나타납니다.
import sun.misc.BASE64Decoder;
public void org() throws Exception{
BASE64Decoder decoder = new BASE64Decoder();
try {
String inputString = "84VWAVDY";
byte[] decodedByteArray = decoder.decodeBuffer(inputString);
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(decodedByteArray);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength);
System.out.println("OUTPUT:" + outputString);
} catch (Exception e){
System.out.println("Exception: " + e);
}
}
이 코드는 기본적으로 Java API의 복사/붙여 넣기입니다. 나는 또한 새로운 Inflater (true)를 사용하려고 시도했다. 즉, nowrap
"참고 : 'nowrap'옵션을 사용하는 경우 추가"더미 "바이트를 입력해야합니다. 이는 특정 최적화를 지원하기 위해 ZLIB 기본 라이브러리에서 필요합니다."
그래서이 더미 바이트는 어디에 추가되어야합니까? "byte [] decodedByteArray"의 처음 또는 끝에?
그래서 어떤 아이디어가이 문제를 해결할 수 있습니까? 더미 바이트 만 추가해야합니까, 다른 methodes 등을 사용해야합니까?
음, 그게 전부입니다, 도움이 감사합니다!
감사
존
그래서 바이트를 추가하려면, 0을 더하고 싶은 데이터보다 하나 더 긴 다른 바이트 []를 만들어야합니다. 그런 다음 원본 배열의 바이트를 새로운 배열로 복사하고 마지막 셀에 0을 추가합니까? – John
예. 일반적으로 데이터를 읽는 원본 버퍼는 적어도 1 바이트 이상 길어지기 때문에 복사본을 만들 필요가 없습니다. –
아, 고마워! – John