Example usage for java.util.zip DeflaterOutputStream DeflaterOutputStream

List of usage examples for java.util.zip DeflaterOutputStream DeflaterOutputStream

Introduction

In this page you can find the example usage for java.util.zip DeflaterOutputStream DeflaterOutputStream.

Prototype

public DeflaterOutputStream(OutputStream out) 

Source Link

Document

Creates a new output stream with a default compressor and buffer size.

Usage

From source file:FileDeflater.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.dat");
    FileOutputStream fout = new FileOutputStream("b.dat");
    DeflaterOutputStream dos = new DeflaterOutputStream(fout);
    for (int c = fin.read(); c != -1; c = fin.read()) {
        dos.write(c);//from   ww w.java2  s .c om
    }
    dos.close();
    fin.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 };
    DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat")));
    fout.writeInt(data.length);//from w w  w. ja  v a2s .  c  o  m

    for (double d : data)
        fout.writeDouble(d);

    DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat")));
    int num = fin.readInt();

    double avg = 0.0;
    double d;

    for (int i = 0; i < num; i++) {
        d = fin.readDouble();
        avg += d;
        System.out.print(d + " ");
    }
    fin.close();
    fout.close();
}

From source file:Main.java

public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
        try {/*from  w  w w  .j  a  va 2 s.  co  m*/
            FileInputStream fin = new FileInputStream(args[i]);
            FileOutputStream fout = new FileOutputStream(args[i] + "dfl");
            DeflaterOutputStream dos = new DeflaterOutputStream(fout);
            for (int c = fin.read(); c != -1; c = fin.read()) {
                dos.write(c);
            }
            dos.close();
            fin.close();
        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        try {/*from   w w  w .  j a v a2 s.c o m*/
            FileInputStream fin = new FileInputStream(args[i]);
            FileOutputStream fout = new FileOutputStream(args[i] + DEFLATE_SUFFIX);
            DeflaterOutputStream dos = new DeflaterOutputStream(fout);
            for (int c = fin.read(); c != -1; c = fin.read()) {
                dos.write(c);
            }
            dos.close();
            fin.close();
        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}

From source file:de.qaware.chronix.spark.api.java.ExternalizeTestData.java

/**
 * @param args optional first argument: file to serialize to. A default file name is provided.
 * @throws SolrServerException//w w  w  .  j  a va 2 s  .  co  m
 * @throws FileNotFoundException
 */
public static void main(String[] args) throws SolrServerException, IOException {

    ChronixSparkLoader chronixSparkLoader = new ChronixSparkLoader();
    ChronixYAMLConfiguration config = chronixSparkLoader.getConfig();

    String file = (args.length >= 1) ? args[0] : config.getTestdataFile();

    Path filePath = Paths.get(file);
    Files.deleteIfExists(filePath);
    Output output = new Output(new DeflaterOutputStream(new FileOutputStream(filePath.toString())));
    System.out.println("Opening test data file: " + filePath.toString());

    ChronixSparkContext cSparkContext = null;

    //Create target file
    try {
        //Create Chronix Spark context
        cSparkContext = chronixSparkLoader.createChronixSparkContext();

        //Read data into ChronixRDD
        SolrQuery query = new SolrQuery(config.getSolrReferenceQuery());
        ChronixRDD rdd = cSparkContext.queryChronixChunks(query, config.getZookeeperHost(),
                config.getChronixCollection(), config.getStorage());

        System.out.println("Writing " + rdd.count() + " time series into test data file.");

        //Loop through result and serialize it to disk
        Kryo kryo = new Kryo();
        List<MetricTimeSeries> mtsList = IteratorUtils.toList(rdd.iterator());
        System.out.println("Writing objects...");
        kryo.writeObject(output, mtsList);
        output.flush();
        System.out.println("Objects written.");
    } finally {
        output.close();
        if (cSparkContext != null) {
            cSparkContext.getSparkContext().close();
        }
        System.out.println("Test data file written successfully!");
    }
}

From source file:de.topobyte.livecg.core.painting.backend.ipe.IpeImageEncoder.java

public static IpeImage encode(Image image) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos);
    for (int j = 0; j < image.getHeight(); j++) {
        for (int i = 0; i < image.getWidth(); i++) {
            int rgb = image.getRGB(i, j);
            dos.write(rgb >> 16);/*from  www.j av  a2 s . com*/
            dos.write(rgb >> 8);
            dos.write(rgb);
        }
    }
    dos.close();
    byte[] buffer = baos.toByteArray();
    int length = buffer.length;

    byte[] bbase64 = Base64.encodeBase64(buffer);
    String base64 = new String(bbase64);

    return new IpeImage(base64, length);
}

From source file:com.jzboy.couchdb.DatabaseDocUpdateTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    dbName = "jzboy_test_db_" + System.currentTimeMillis();
    instance = new Database(dbName);
    instance.create();// ww w.  j av  a 2  s . c o m

    // create a gzipped attachment
    final String inputString = "blahblahblah??";
    byte[] input = inputString.getBytes("utf-8");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DeflaterOutputStream deflater = new DeflaterOutputStream(os);
    deflater.write(input, 0, input.length);
    deflater.close();
    attachment = os.toByteArray();
}

From source file:util.RequestUtil.java

/**
 * Generates an encoded and compressed String from the specified XML-formatted
 * String. The String is encoded in the following order:
 * <p>/*w  w  w .  jav a 2s.  c o m*/
 * 1. URL encode <br>
 * 2. Base64 encode <br>
 * 3. Deflate <br>
 * 
 * @param xmlString XML-formatted String that is to be encoded
 * @return String containing the encoded contents of the specified XML String
 */
public static String encodeMessage(String xmlString) throws IOException, UnsupportedEncodingException {
    // first DEFLATE compress the document (saml-bindings-2.0,
    // section 3.4.4.1)
    byte[] xmlBytes = xmlString.getBytes("UTF-8");
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();

    // next, base64 encode it
    Base64 base64Encoder = new Base64();
    byte[] base64EncodedByteArray = base64Encoder.encode(byteOutputStream.toByteArray());
    String base64EncodedMessage = new String(base64EncodedByteArray);

    // finally, URL encode it
    String urlEncodedMessage = URLEncoder.encode(base64EncodedMessage, "UTF-8");

    return urlEncodedMessage;
}

From source file:net.paygate.saml.util.RequestUtil.java

/**
 * Generates an encoded and compressed String from the specified XML-formatted
 * String. The String is encoded in the following order:
 * <p>/*from w w w.  j  a v a  2  s .co m*/
 * 1. URL encode <br>
 * 2. Base64 encode <br>
 * 3. Deflate <br>
 * 
 * @param xmlString XML-formatted String that is to be encoded
 * @return String containing the encoded contents of the specified XML String
 */
public static String encodeMessage(String xmlString) throws IOException, UnsupportedEncodingException {
    // first DEFLATE compress the document (saml-bindings-2.0,
    // section 3.4.4.1)
    byte[] xmlBytes = xmlString.getBytes("UTF-8");
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();

    // next, base64 encode it
    Base64 base64Encoder = new Base64();
    byte[] base64EncodedByteArray = base64Encoder.encode(byteOutputStream.toByteArray());
    String base64EncodedMessage = new String(base64EncodedByteArray);

    // finally, URL encode it
    String urlEncodedMessage = URLEncoder.encode(base64EncodedMessage);

    return urlEncodedMessage;
}

From source file:com.integrareti.integraframework.util.RequestUtil.java

/**
 * Generates an encoded and compressed String from the specified
 * XML-formatted String. The String is encoded in the following order:
 * <p>/*from  w w  w. j av  a2s  .com*/
 * 1. URL encode <br>
 * 2. Base64 encode <br>
 * 3. Deflate <br>
 * 
 * @param xmlString
 *            XML-formatted String that is to be encoded
 * @return String containing the encoded contents of the specified XML
 *         String
 */
public static String encodeMessage(String xmlString) throws IOException, UnsupportedEncodingException {
    // first DEFLATE compress the document (saml-bindings-2.0,
    // section 3.4.4.1)
    byte[] xmlBytes = xmlString.getBytes("UTF-8");
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();
    // next, base64 encode it
    Base64 base64Encoder = new Base64();
    byte[] base64EncodedByteArray = base64Encoder.encode(byteOutputStream.toByteArray());
    String base64EncodedMessage = new String(base64EncodedByteArray);
    // finally, URL encode it
    String urlEncodedMessage = URLEncoder.encode(base64EncodedMessage, "UTF-8");
    return urlEncodedMessage;
}