Examples of DeflaterOutputStream


Examples of java.util.zip.DeflaterOutputStream

    if (!StringChecker.validString(zoneid)) {
      throw new SQLException("Invalid string zoneid=(" + zoneid + ")");
    }

    ByteArrayOutputStream array = new ByteArrayOutputStream();
    DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    OutputSerializer os = new OutputSerializer(out_stream);

    /* compute how many storable objects exists in zone. */
    int amount = 0;
    for (RPObject object : content) {
      if (object.isStorable()) {
        amount++;
      }
    }

    os.write(amount);

    boolean empty = true;
    for (RPObject object : content) {
      if (object.isStorable()) {
        object.writeObject(os, DetailLevel.FULL);
        empty = false;
      }
    }

    out_stream.close();

    /* Setup the stream for a blob */
    ByteArrayInputStream inStream = new ByteArrayInputStream(array.toByteArray());

    String query;
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

  @Override
  public void writeObject(marauroa.common.net.OutputSerializer out) throws IOException {
    super.writeObject(out);

    ByteArrayOutputStream array = new ByteArrayOutputStream();
    DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    OutputSerializer serializer = new OutputSerializer(out_stream);
    serializer.setProtocolVersion(out.getProtocolVersion());

    serializer.write(contents);
    int size = RPClass.size();

    // sort out the default rp class if it is there
    for (Iterator<RPClass> it = RPClass.iterator(); it.hasNext();) {
      RPClass rp_class = it.next();
      if ("".equals(rp_class.getName())) {
        size--;
        break;
      }
    }

    serializer.write(size);
    for (Iterator<RPClass> it = RPClass.iterator(); it.hasNext();) {
      RPClass rp_class = it.next();
      if (!"".equals(rp_class.getName())) // sort out default class if it
      // is there
      {
        serializer.write(rp_class);
      }
    }

    out_stream.close();

    out.write(array.toByteArray());
  }
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

  
   protected byte[] deflate(Object object) throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      Deflater def = new Deflater(java.util.zip.Deflater.BEST_COMPRESSION);
      DeflaterOutputStream dos = new DeflaterOutputStream(baos, def);
     
      ObjectOutputStream out = new ObjectOutputStream(dos);
      out.writeObject(object);
      out.close();
      dos.finish();
      dos.close();
     
      return baos.toByteArray();
   }
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

            }

            // Debug.debug("uncompressed", uncompressed.length);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DeflaterOutputStream dos = new DeflaterOutputStream(baos);
            int chunk_size = 256 * 1024;
            for (int index = 0; index < uncompressed.length; index += chunk_size)
            {
                int end = Math.min(uncompressed.length, index + chunk_size);
                int length = end - index;

                dos.write(uncompressed, index, length);
                dos.flush();
                baos.flush();

                byte compressed[] = baos.toByteArray();
                baos.reset();
                if (compressed.length > 0)
                {
                    // Debug.debug("compressed", compressed.length);
                    writeChunkIDAT(os, compressed);
                }

            }
            {
                dos.finish();
                byte compressed[] = baos.toByteArray();
                if (compressed.length > 0)
                {
                    // Debug.debug("compressed final", compressed.length);
                    writeChunkIDAT(os, compressed);
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

  {
    try
    {
      ByteArrayInputStream inputStream = new ByteArrayInputStream(data, offset, length);
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      DeflaterOutputStream outputFilter = new DeflaterOutputStream(outputStream);
      transform(inputStream, outputFilter);
      return outputStream.toByteArray();
    }
    catch(IOException e)
    {throw new RuntimeException("Encoding failed.",e);}
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

                               int compressionType) throws IOException {

        InputStream          in        = null;
        OutputStream         f         = null;
        OutputStream         fOut      = null;
        DeflaterOutputStream deflater  = null;
        boolean              completed = false;

        // if there is no file
        if (!storage.isStreamElement(infilename)) {
            return;
        }

        try {
            byte[] b = new byte[COPY_BLOCK_SIZE];

            in   = storage.openInputStreamElement(infilename);
            f    = storage.openOutputStreamElement(outfilename);
            fOut = f;

            switch (compressionType) {

                case COMPRESSION_ZIP :
                    f = deflater = new DeflaterOutputStream(f,
                            new Deflater(Deflater.BEST_SPEED), b.length);
                    break;

                case COMPRESSION_GZIP :
                    f = deflater = new GZIPOutputStream(f, b.length);
                    break;

                case COMPRESSION_NONE :
                    break;

                default :
                    throw new RuntimeException("FileArchiver"
                                               + compressionType);
            }

            while (true) {
                int l = in.read(b, 0, b.length);

                if (l == -1) {
                    break;
                }

                f.write(b, 0, l);
            }

            completed = true;
        } catch (Throwable e) {
            throw JavaSystem.toIOException(e);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }

                if (f != null) {
                    if (deflater != null) {
                        deflater.finish();
                    }

                    if (fOut instanceof FileOutputStream) {
                        storage.getFileSync(fOut).sync();
                    }
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

                        final boolean changed = isChanged(current, previous, x0, y0, bwidth, bheight, width, height);

                        if (changed) {
                            ByteArrayOutputStream blaos = new ByteArrayOutputStream(4 * 1024);

                            DeflaterOutputStream dos = new DeflaterOutputStream(blaos);

                            for (int y = 0; y < bheight; y++) {
                                dos.write(current, 3 * ((y0 + bheight - y - 1) * width + x0), 3 * bwidth);
                            }

                            dos.finish();

                            final byte[] bbuf = blaos.toByteArray();
                            final int written = bbuf.length;

                            // write DataSize
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

          if (changed)
          {
            ByteArrayOutputStream blaos = new ByteArrayOutputStream(4 * 1024);

            DeflaterOutputStream dos = new DeflaterOutputStream(blaos);

            for (int y = 0; y < bheight; y++)
            {
              dos.write(current, 3 * ((y0 + bheight - y - 1) * width + x0), 3 * bwidth);
            }

            dos.finish();

            final byte[] bbuf = blaos.toByteArray();
            final int written = bbuf.length;

            // write DataSize
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

   * @return the encode byte array
   * @throws IOException
   */
  public byte[] encode() throws IOException {
    final ByteArrayOutputStream array = new ByteArrayOutputStream();
    final DeflaterOutputStream out_stream = new DeflaterOutputStream(array);
    final OutputSerializer out = new OutputSerializer(out_stream);

    writeObject(out);
    out_stream.close();

    return array.toByteArray();
  }
View Full Code Here

Examples of java.util.zip.DeflaterOutputStream

   
      _out.writeInt(0);

      _bodyOut = _out.getBytesOutputStream();
   
      _deflateOut = new DeflaterOutputStream(_bodyOut);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.