Search in sources :

Example 81 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project knox by apache.

the class UrlRewriteResponseTest method testStreamResponse.

private void testStreamResponse(String content, UrlRewriteResponse rewriteResponse, String contentType) throws IOException {
    Path inputFile = Files.createTempFile("input", "test");
    Path outputFile = Files.createTempFile("output", "test");
    try {
        try (OutputStream outputStream = Files.newOutputStream(inputFile);
            OutputStream outStream = "gzip".equalsIgnoreCase(contentType) ? new GZIPOutputStream(outputStream) : "deflate".equalsIgnoreCase(contentType) ? new DeflaterOutputStream(outputStream) : outputStream) {
            outStream.write(content.getBytes(StandardCharsets.UTF_8));
        }
        try (InputStream input = Files.newInputStream(inputFile);
            OutputStream output = Files.newOutputStream(outputFile)) {
            rewriteResponse.streamResponse(input, output);
        }
        try (InputStream inputStream = Files.newInputStream(outputFile);
            InputStream inStream = "gzip".equalsIgnoreCase(contentType) ? new GZIPInputStream(inputStream) : "deflate".equalsIgnoreCase(contentType) ? new InflaterInputStream(inputStream) : inputStream) {
            assertThat(String.valueOf(IOUtils.toCharArray(inStream, StandardCharsets.UTF_8)), is(content));
        }
    } finally {
        Files.delete(inputFile);
        Files.delete(outputFile);
    }
}
Also used : Path(java.nio.file.Path) GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 82 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project litiengine by gurkenlabs.

the class TileData method encodeBase64.

private static String encodeBase64(TileData data) throws IOException {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        OutputStream out = baos;
        if (data.getCompression() != null && Compression.isValid(data.getCompression())) {
            if (data.getCompression().equals(Compression.GZIP)) {
                out = new GZIPOutputStream(baos);
            } else if (data.getCompression().equals(Compression.ZLIB)) {
                out = new DeflaterOutputStream(baos);
            }
        }
        for (Tile tile : data.getTiles()) {
            int gid = 0;
            if (tile != null) {
                gid = tile.getGridId();
            }
            out.write(gid);
            out.write(gid >> Byte.SIZE);
            out.write(gid >> Byte.SIZE * 2);
            out.write(gid >> Byte.SIZE * 3);
        }
        if (data.getCompression() != null && data.getCompression().equals(Compression.GZIP)) {
            ((GZIPOutputStream) out).finish();
        }
        if (data.getCompression() != null && data.getCompression().equals(Compression.ZLIB)) {
            ((DeflaterOutputStream) out).finish();
        }
        return Codec.encode(baos.toByteArray());
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 83 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project iaf by ibissource.

the class JdbcUtil method getBlobWriter.

public static Writer getBlobWriter(IDbmsSupport dbmsSupport, Object blobUpdateHandle, final ResultSet rs, int columnIndex, String charset, boolean compressBlob) throws IOException, JdbcException, SQLException {
    Writer result;
    OutputStream out = dbmsSupport.getBlobOutputStream(rs, columnIndex, blobUpdateHandle);
    if (charset == null) {
        charset = StreamUtil.DEFAULT_INPUT_STREAM_ENCODING;
    }
    if (compressBlob) {
        result = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(out), charset));
    } else {
        result = new BufferedWriter(new OutputStreamWriter(out, charset));
    }
    return result;
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 84 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project iaf by ibissource.

the class JdbcUtil method putByteArrayAsBlob.

public static void putByteArrayAsBlob(IDbmsSupport dbmsSupport, final ResultSet rs, int columnIndex, byte[] content, boolean compressBlob) throws IOException, JdbcException, SQLException {
    if (content != null) {
        Object blobHandle = dbmsSupport.getBlobHandle(rs, columnIndex);
        try (OutputStream out = dbmsSupport.getBlobOutputStream(rs, columnIndex, blobHandle)) {
            if (compressBlob) {
                try (DeflaterOutputStream dos = new DeflaterOutputStream(out)) {
                    dos.write(content);
                }
            } else {
                out.write(content);
            }
        }
        dbmsSupport.updateBlob(rs, columnIndex, blobHandle);
    } else {
        log.warn("content to store in blob was null");
    }
}
Also used : DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream)

Example 85 with DeflaterOutputStream

use of java.util.zip.DeflaterOutputStream in project iaf by ibissource.

the class JdbcTransactionalStorageTest method testQueryTextAndBrowseMessageHelper.

public void testQueryTextAndBrowseMessageHelper(boolean blobsCompressed) throws Exception {
    storage.setBlobsCompressed(blobsCompressed);
    storage.configure();
    // check created query
    String expected = "SELECT " + keyField + "," + messageField + " FROM " + tableName + " WHERE " + keyField + "=?";
    String query = storage.selectDataQuery;
    assertEquals(expected, query);
    Message message = createMessage();
    String storageKey = null;
    // insert a record
    try (Connection connection = getConnection()) {
        try (PreparedStatement stmt = prepareStatement(connection)) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStream out = blobsCompressed ? new DeflaterOutputStream(baos) : baos;
            try (ObjectOutputStream oos = new ObjectOutputStream(out)) {
                oos.writeObject(message);
            }
            stmt.setBytes(1, baos.toByteArray());
            stmt.execute();
            try (ResultSet rs = stmt.getGeneratedKeys()) {
                if (rs.next()) {
                    // check inserted data being correctly retrieved
                    storageKey = rs.getString(1);
                } else {
                    Assert.fail("The query [" + storage.selectDataQuery + "] returned empty result set expected 1");
                }
            }
        }
    }
    Message data = storage.browseMessage(storageKey);
    assertEquals(message.asString(), data.asString());
}
Also used : Message(nl.nn.adapterframework.stream.Message) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Connection(java.sql.Connection) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

DeflaterOutputStream (java.util.zip.DeflaterOutputStream)162 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 Deflater (java.util.zip.Deflater)63 IOException (java.io.IOException)52 OutputStream (java.io.OutputStream)39 DataOutputStream (java.io.DataOutputStream)21 InflaterInputStream (java.util.zip.InflaterInputStream)16 GZIPOutputStream (java.util.zip.GZIPOutputStream)12 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)8 InputStream (java.io.InputStream)7 ObjectOutputStream (java.io.ObjectOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileInputStream (java.io.FileInputStream)6 BufferedOutputStream (java.io.BufferedOutputStream)5 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)5 Saml2Exception (org.springframework.security.saml2.Saml2Exception)5 ByteBuffer (java.nio.ByteBuffer)4 EOFException (java.io.EOFException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3