56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
package io.github.lonamiwebs.overgram.tl;
|
|
|
|
import io.github.lonamiwebs.overgram.utils.BinaryReader;
|
|
import io.github.lonamiwebs.overgram.utils.BinaryWriter;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.zip.GZIPInputStream;
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
public class GzipPacked extends TLObject {
|
|
public static final int CONSTRUCTOR_ID = 812830625;
|
|
|
|
public byte[] unpackedData;
|
|
|
|
@Override
|
|
public void serialize(final BinaryWriter writer) {
|
|
try {
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
final GZIPOutputStream gzip = new GZIPOutputStream(out);
|
|
gzip.write(unpackedData);
|
|
gzip.finish();
|
|
writer.write(out.toByteArray());
|
|
} catch (IOException ignored) {
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void deserialize(final BinaryReader reader) throws ClassNotFoundException {
|
|
try {
|
|
final GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(reader.read()));
|
|
final ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
|
final byte[] buffer = new byte[4096];
|
|
int read;
|
|
while ((read = gzip.read(buffer)) != -1) {
|
|
out.write(buffer, 0, read);
|
|
}
|
|
unpackedData = out.toByteArray();
|
|
} catch (IOException ignored) {
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
|
|
public static byte[] unzip(final BinaryReader reader) {
|
|
final GzipPacked gzipPacked = new GzipPacked();
|
|
try {
|
|
gzipPacked.deserialize(reader);
|
|
} catch (ClassNotFoundException ignored) {
|
|
throw new RuntimeException();
|
|
}
|
|
return gzipPacked.unpackedData;
|
|
}
|
|
}
|