Package com.mxgraph.imageexport

Source Code of com.mxgraph.imageexport.Utils

/**
* Copyright (c) 2010-2013, JGraph Ltd
*/
package com.mxgraph.imageexport;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

/**
* General utilities using for image generation
*/
public class Utils
{
  protected static final int IO_BUFFER_SIZE = 4 * 1024;

  public static String inflate(byte[] binary) throws IOException
  {
    StringBuffer result = new StringBuffer();
    InputStream in = new InflaterInputStream(new ByteArrayInputStream(
        binary), new Inflater(true));

    while (in.available() != 0)
    {
      byte[] buffer = new byte[IO_BUFFER_SIZE];
      int len = in.read(buffer, 0, IO_BUFFER_SIZE);

      if (len <= 0)
      {
        break;
      }

      result.append(new String(buffer, 0, len));
    }

    in.close();

    return result.toString();
  }

}
TOP

Related Classes of com.mxgraph.imageexport.Utils

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.