use of java.util.zip.DeflaterOutputStream in project freeplane by freeplane.
the class Dictionary method save.
/**
* Save this dictionary to the OutputStream. The data will be compressed. After finish the OutputStream is closed.
* @param stream the OutputStream
* @throws IOException if an I/O error occurs.
*/
public void save(final OutputStream stream) throws IOException {
final Deflater deflater = new Deflater();
deflater.setLevel(Deflater.BEST_COMPRESSION);
final DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
for (int i = 0; i < size; i++) {
zip.write(tree[i]);
zip.write(tree[i] >> 8);
}
zip.flush();
zip.close();
}
use of java.util.zip.DeflaterOutputStream in project navajo by Dexels.
the class JavaNetNavajoClientImpl method postNavajo.
private void postNavajo(Navajo inputNavajo, boolean useCompression, HttpURLConnection con) throws IOException {
if (useCompression) {
if (forceGzip) {
con.setRequestProperty("Content-Encoding", "gzip");
con.setRequestProperty("Accept-Encoding", "gzip");
} else {
con.setChunkedStreamingMode(1024);
con.setRequestProperty("Transfer-Encoding", "chunked");
con.setRequestProperty("Content-Encoding", "jzlib");
con.setRequestProperty("Accept-Encoding", "jzlib");
}
BufferedWriter out = null;
try {
if (forceGzip) {
out = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(con.getOutputStream()), StandardCharsets.UTF_8));
} else {
out = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(con.getOutputStream()), StandardCharsets.UTF_8));
}
inputNavajo.write(out);
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
logger.error("Error: ", e);
}
}
}
} else {
con.setRequestProperty("noCompression", "true");
try (BufferedWriter os = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), StandardCharsets.UTF_8))) {
inputNavajo.write(os);
}
}
}
use of java.util.zip.DeflaterOutputStream in project pdfbox by apache.
the class FlateFilter method encode.
@Override
protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters) throws IOException {
int compressionLevel = getCompressionLevel();
Deflater deflater = new Deflater(compressionLevel);
try (DeflaterOutputStream out = new DeflaterOutputStream(encoded, deflater)) {
IOUtils.copy(input, out);
}
encoded.flush();
deflater.end();
}
use of java.util.zip.DeflaterOutputStream in project jjwt by jwtk.
the class DeflateCompressionCodec method doCompress.
@Override
public byte[] doCompress(byte[] payload) throws IOException {
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
ByteArrayOutputStream outputStream = null;
DeflaterOutputStream deflaterOutputStream = null;
try {
outputStream = new ByteArrayOutputStream();
deflaterOutputStream = new DeflaterOutputStream(outputStream, deflater, true);
deflaterOutputStream.write(payload, 0, payload.length);
deflaterOutputStream.flush();
return outputStream.toByteArray();
} finally {
Objects.nullSafeClose(outputStream, deflaterOutputStream);
}
}
use of java.util.zip.DeflaterOutputStream in project bigbluebutton by bigbluebutton.
the class ScreenVideoEncoder method encodePixelsSVC2.
public static byte[] encodePixelsSVC2(int[] pixels, int width, int height) {
changePixelScanFromBottomLeftToTopRight(pixels, width, height);
if (paletteIndex == null)
createPaletteIndex();
try {
// TODO calibrate initial size
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
for (int i = 0; i < pixels.length; i++) {
writeAs15_7(pixels[i], baos1);
}
// baos2 contains everything from IMAGEBLOCKV2 except the DataSize field
// TODO calibrate initial size
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
// IMAGEFORMAT:
// ColorDepth: UB[2] 10 (15/7 hybrid color image); HasDiffBlocks: UB[1] 0; Zlib prime stuff (2 bits) not used (0)
baos2.write(16);
// No ImageBlockHeader (IMAGEDIFFPOSITION, IMAGEPRIMEPOSITION)
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
DeflaterOutputStream deflateroutputstream = new DeflaterOutputStream(baos2, deflater);
deflateroutputstream.write(baos1.toByteArray());
deflateroutputstream.finish();
byte[] dataBuffer = baos2.toByteArray();
// DataSize field
int dataSize = dataBuffer.length;
// TODO calibrate initial size
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeShort(((OutputStream) (baos)), dataSize);
// Data
baos.write(dataBuffer, 0, dataSize);
return baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations