use of java.util.zip.DeflaterOutputStream in project poi by apache.
the class EscherMetafileBlip method setPictureData.
@Override
public void setPictureData(byte[] pictureData) {
super.setPictureData(pictureData);
setUncompressedSize(pictureData.length);
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(bos);
dos.write(pictureData);
dos.close();
raw_pictureData = bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Can't compress metafile picture data", e);
}
setCompressedSize(raw_pictureData.length);
setCompressed(true);
}
use of java.util.zip.DeflaterOutputStream in project voltdb by VoltDB.
the class ScriptWriterZipped method openFile.
protected void openFile() {
try {
FileAccess fa = database.getFileAccess();
java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
outDescriptor = fa.getFileSync(fos);
fileStreamOut = new DeflaterOutputStream(fos, new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
} catch (IOException e) {
throw Error.error(ErrorCode.FILE_IO_ERROR, ErrorCode.M_Message_Pair, new Object[] { e.toString(), outFile });
}
}
use of java.util.zip.DeflaterOutputStream in project jdk8u_jdk by JetBrains.
the class PNGImageWriter method deflate.
private byte[] deflate(byte[] b) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
dos.write(b);
dos.close();
return baos.toByteArray();
}
use of java.util.zip.DeflaterOutputStream in project simba-os by cegeka.
the class SAMLServiceImpl method encodeSAMLRequest.
protected String encodeSAMLRequest(byte[] pSAMLRequest) throws RuntimeException {
Base64 base64Encoder = new Base64();
try {
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
DeflaterOutputStream def = new DeflaterOutputStream(byteArray, deflater);
def.write(pSAMLRequest);
def.close();
byteArray.close();
String stream = new String(base64Encoder.encode(byteArray.toByteArray()));
return stream.trim();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.util.zip.DeflaterOutputStream in project ddf by codice.
the class SimpleSignTest method deflateAndBase64Encode.
/**
* Deflates a value and Base64 encodes the result. This code is copied from RestSecurity because it would cause a circular dependency to use it directly..
*
* @param value value to deflate and Base64 encode
* @return String
* @throws IOException if the value cannot be converted
*/
public static String deflateAndBase64Encode(String value) throws IOException {
ByteArrayOutputStream valueBytes = new ByteArrayOutputStream();
try (OutputStream tokenStream = new DeflaterOutputStream(valueBytes, new Deflater(Deflater.DEFLATED, true))) {
tokenStream.write(value.getBytes(StandardCharsets.UTF_8));
tokenStream.close();
return Base64.getEncoder().encodeToString(valueBytes.toByteArray());
}
}
Aggregations