Java Code Examples for java.util.zip.GZIPOutputStream

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/helper/.

Source file: GZIPHelper.java

  33 
vote

public byte[] zippedSession(Session session) throws IOException {
  ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
  Base64OutputStream base64OutputStream=new Base64OutputStream(byteStream);
  GZIPOutputStream gzip=new GZIPOutputStream(base64OutputStream);
  OutputStreamWriter writer=new OutputStreamWriter(gzip);
  gson.toJson(session,session.getClass(),writer);
  writer.flush();
  gzip.finish();
  writer.close();
  return byteStream.toByteArray();
}
 

Example 2

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/picasa/.

Source file: GDataClient.java

  32 
vote

private ByteArrayEntity getCompressedEntity(byte[] data) throws IOException {
  ByteArrayEntity entity;
  if (data.length >= MIN_GZIP_SIZE) {
    ByteArrayOutputStream byteOutput=new ByteArrayOutputStream(data.length / 2);
    GZIPOutputStream gzipOutput=new GZIPOutputStream(byteOutput);
    gzipOutput.write(data);
    gzipOutput.close();
    entity=new ByteArrayEntity(byteOutput.toByteArray());
  }
 else {
    entity=new ByteArrayEntity(data);
  }
  return entity;
}
 

Example 3

From project capedwarf-green, under directory /common/src/main/java/org/jboss/capedwarf/common/serialization/.

Source file: GzipOptionalSerializator.java

  32 
vote

public void serialize(Object instance,OutputStream out) throws IOException {
  if (isGzipEnabled()) {
    GZIPOutputStream gzip=new GZIPOutputStream(out);
    delegate.serialize(instance,gzip);
    gzip.finish();
  }
 else {
    delegate.serialize(instance,out);
  }
}
 

Example 4

From project crammer, under directory /src/main/java/uk/ac/ebi/ena/sra/cram/impl/.

Source file: CramWriter.java

  32 
vote

private void flushWriterOS() throws IOException {
  ExposedByteArrayOutputStream compressedOS=new ExposedByteArrayOutputStream(1024);
  GZIPOutputStream gos=new GZIPOutputStream(compressedOS);
  gos.write(writerOS.getBuffer(),0,writerOS.size());
  gos.close();
  writerOS.reset();
  DataOutputStream dos=new DataOutputStream(os);
  dos.writeInt(compressedOS.size());
  dos.write(compressedOS.getBuffer(),0,compressedOS.size());
  dos.flush();
}
 

Example 5

From project curator, under directory /curator-framework/src/main/java/com/netflix/curator/framework/imps/.

Source file: GzipCompressionProvider.java

  32 
vote

@Override public byte[] compress(String path,byte[] data) throws Exception {
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  GZIPOutputStream out=new GZIPOutputStream(bytes);
  out.write(data);
  out.finish();
  return bytes.toByteArray();
}
 

Example 6

From project daap, under directory /src/main/java/org/ardverk/daap/.

Source file: DaapUtil.java

  32 
vote

/** 
 * Serializes the <code>chunk</code> and compresses it optionally. The serialized data is returned as a byte-Array.
 */
public static final byte[] serialize(Chunk chunk,boolean compress) throws IOException {
  ByteArrayOutputStream buffer=new ByteArrayOutputStream(255);
  DaapOutputStream out=null;
  if (DaapUtil.COMPRESS && compress) {
    GZIPOutputStream gzip=new GZIPOutputStream(buffer);
    out=new DaapOutputStream(gzip);
  }
 else {
    out=new DaapOutputStream(buffer);
  }
  out.writeChunk(chunk);
  out.close();
  return buffer.toByteArray();
}
 

Example 7

From project echo2, under directory /src/webrender/java/nextapp/echo2/webrender/util/.

Source file: GZipCompressor.java

  32 
vote

/** 
 * Compresses a String.
 * @param s the String to compress
 * @return an array of bytes containing GZip-compression output
 * @throws IOException
 */
public static byte[] compress(String s) throws IOException {
  ByteArrayOutputStream byteOut=new ByteArrayOutputStream();
  GZIPOutputStream gZipOut=new GZIPOutputStream(byteOut);
  gZipOut.write(s.getBytes());
  gZipOut.finish();
  byteOut.close();
  return byteOut.toByteArray();
}
 

Example 8

From project echo3, under directory /src/server-java/webcontainer/nextapp/echo/webcontainer/util/.

Source file: GZipCompressor.java

  32 
vote

/** 
 * Compresses a String.
 * @param s the String to compress
 * @return an array of bytes containing GZip-compression output
 * @throws IOException
 */
public static byte[] compress(String s) throws IOException {
  ByteArrayOutputStream byteOut=new ByteArrayOutputStream();
  GZIPOutputStream gZipOut=new GZIPOutputStream(byteOut);
  gZipOut.write(s.getBytes());
  gZipOut.finish();
  byteOut.close();
  return byteOut.toByteArray();
}
 

Example 9

From project erjang, under directory /src/main/java/erjang/driver/.

Source file: IO.java

  32 
vote

/** 
 * @param fd
 * @param byteBuffer
 * @return
 * @throws InterruptedException
 */
public static long gzwrite(WritableByteChannel fd,ByteBuffer src) throws IOException {
  long result=src.remaining();
  BARR barr=new BARR();
  GZIPOutputStream go=new GZIPOutputStream(barr);
  IO.write(go,src);
  go.close();
  src=barr.wrap();
  writeFully(fd,src);
  if (src.hasRemaining()) {
    throw new Error("should not happen");
  }
  return result;
}
 

Example 10

From project Flume-Hive, under directory /src/java/com/cloudera/flume/handlers/batch/.

Source file: GzipDecorator.java

  32 
vote

@Override public void append(Event e) throws IOException {
  WriteableEvent we=new WriteableEvent(e);
  byte[] bs=we.toBytes();
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gzos=new GZIPOutputStream(baos);
  gzos.write(bs);
  gzos.close();
  Event gze=new EventImpl(new byte[0]);
  gze.set(GunzipDecorator.GZDOC,baos.toByteArray());
  super.append(gze);
}
 

Example 11

From project graylog2-server, under directory /src/test/java/org/graylog2/.

Source file: TestHelper.java

  32 
vote

public static byte[] gzipCompress(String what) throws IOException {
  ByteArrayInputStream compressMe=new ByteArrayInputStream(what.getBytes("UTF-8"));
  ByteArrayOutputStream compressedMessage=new ByteArrayOutputStream();
  GZIPOutputStream out=new GZIPOutputStream(compressedMessage);
  for (int c=compressMe.read(); c != -1; c=compressMe.read()) {
    out.write(c);
  }
  out.close();
  return compressedMessage.toByteArray();
}
 

Example 12

From project heritrix3, under directory /commons/src/main/java/org/archive/util/.

Source file: ArchiveUtils.java

  32 
vote

/** 
 * Gzip passed bytes. Use only when bytes is small.
 * @param bytes What to gzip.
 * @return A gzip member of bytes.
 * @throws IOException
 */
public static byte[] gzip(byte[] bytes) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gzipOS=new GZIPOutputStream(baos);
  gzipOS.write(bytes,0,bytes.length);
  gzipOS.close();
  return baos.toByteArray();
}
 

Example 13

From project httpClient, under directory /httpclient/src/main/java/org/apache/http/client/entity/.

Source file: GzipCompressingEntity.java

  32 
vote

@Override public void writeTo(final OutputStream outstream) throws IOException {
  if (outstream == null) {
    throw new IllegalArgumentException("Output stream may not be null");
  }
  GZIPOutputStream gzip=new GZIPOutputStream(outstream);
  try {
    wrappedEntity.writeTo(gzip);
  }
  finally {
    gzip.close();
  }
}
 

Example 14

From project jPOS, under directory /jpos/src/main/java/org/jpos/iso/channel/.

Source file: GZIPChannel.java

  32 
vote

protected void sendMessage(byte[] b,int offset,int len) throws IOException {
  GZIPOutputStream gzip=new GZIPOutputStream(serverOut);
  gzip.write(b,offset,len);
  gzip.finish();
  gzip.flush();
}
 

Example 15

From project jredis, under directory /core/ri/src/main/java/org/jredis/ri/alphazero/support/.

Source file: GZip.java

  32 
vote

/** 
 * @param data
 * @return
 */
public static final byte[] compress(byte[] data){
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  try {
    GZIPOutputStream gzipOutputtStream=new GZIPOutputStream(out);
    gzipOutputtStream.write(data);
    gzipOutputtStream.close();
  }
 catch (  IOException e) {
    throw new RuntimeException("Failed to GZip compress data",e);
  }
  return out.toByteArray();
}
 

Example 16

From project lilith, under directory /lilith/src/main/java/de/huxhorn/lilith/tools/.

Source file: ImportExportCommand.java

  32 
vote

private static void writePersistence(File file,LilithPreferences p) throws IOException {
  GZIPOutputStream os=null;
  try {
    os=new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    LilithPreferencesStreamingEncoder encoder=new LilithPreferencesStreamingEncoder();
    encoder.encode(p,os);
  }
  finally {
    if (os != null) {
      os.close();
    }
  }
}
 

Example 17

From project miso-lims, under directory /integration-tools/src/main/java/uk/ac/bbsrc/tgac/miso/integration/util/.

Source file: IntegrationUtils.java

  32 
vote

public static byte[] compress(byte[] content){
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  Base64OutputStream b64os=new Base64OutputStream(baos);
  try {
    GZIPOutputStream gzip=new GZIPOutputStream(b64os);
    gzip.write(content);
    gzip.close();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  return baos.toByteArray();
}
 

Example 18

From project rewrite, under directory /impl-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/response/.

Source file: GZipResponseStreamWrapper.java

  32 
vote

@Override public OutputStream wrap(HttpServletRewrite rewrite,OutputStream outputStream){
  rewrite.getResponse().addHeader("Content-Encoding","gzip");
  try {
    GZIPOutputStream stream=new FlushableGZIPOutputStream(outputStream);
    return stream;
  }
 catch (  IOException e) {
    throw new RewriteException("Could not wrap OutputStream",e);
  }
}
 

Example 19

From project sensei, under directory /sensei-core/src/main/java/com/sensei/search/req/protobuf/.

Source file: SenseiGenericBPOConverter.java

  32 
vote

public static byte[] compress(byte[] b) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gzos=new GZIPOutputStream(baos);
  gzos.write(b);
  gzos.close();
  byte[] output=baos.toByteArray();
  return output;
}
 

Example 20

From project ServiceFramework, under directory /src/net/csdn/modules/compress/gzip/.

Source file: GZip.java

  32 
vote

public static byte[] encodeWithGZip(String str){
  try {
    ByteArrayOutputStream out=new ByteArrayOutputStream();
    GZIPOutputStream gzipOutputStream=new GZIPOutputStream(out);
    gzipOutputStream.write(str.getBytes("utf-8"));
    gzipOutputStream.close();
    return out.toByteArray();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return str.getBytes();
}
 

Example 21

From project spring-webflow, under directory /spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/.

Source file: SerializedFlowExecutionSnapshot.java

  32 
vote

/** 
 * Internal helper method to compress given flow execution data using GZIP compression. Override if custom compression is desired.
 */
protected byte[] compress(byte[] dataToCompress) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gzipos=new GZIPOutputStream(baos);
  try {
    gzipos.write(dataToCompress);
    gzipos.flush();
  }
  finally {
    gzipos.close();
  }
  return baos.toByteArray();
}
 

Example 22

From project summer, under directory /modules/core/src/main/java/com/asual/summer/core/util/.

Source file: ObjectUtils.java

  32 
vote

public static byte[] compress(Object obj) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gz=new GZIPOutputStream(baos);
  ObjectOutputStream oos=new ObjectOutputStream(gz);
  oos.writeObject(obj);
  oos.close();
  return baos.toByteArray();
}
 

Example 23

From project syncany, under directory /syncany/src/org/syncany/util/.

Source file: FileUtil.java

  32 
vote

public static byte[] gzip(byte[] content) throws IOException {
  ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
  GZIPOutputStream gzipOutputStream=new GZIPOutputStream(byteArrayOutputStream);
  gzipOutputStream.write(content);
  gzipOutputStream.close();
  return byteArrayOutputStream.toByteArray();
}
 

Example 24

From project wordnik-oss, under directory /modules/mongo-admin-utils/src/main/java/com/wordnik/util/.

Source file: GZipUtil.java

  32 
vote

public static void createArchive(String outputFilename,String inputFile) throws IOException {
  GZIPOutputStream out=new GZIPOutputStream(new FileOutputStream(outputFilename));
  byte[] buf=new byte[1024];
  File file=new File(inputFile);
  FileInputStream in=new FileInputStream(file);
  int len;
  while ((len=in.read(buf)) > 0) {
    out.write(buf,0,len);
  }
  in.close();
  out.close();
}
 

Example 25

From project zoie, under directory /zoie-core/src/main/java/proj/zoie/store/.

Source file: AbstractZoieStore.java

  32 
vote

public static byte[] compress(byte[] src) throws IOException {
  ByteArrayOutputStream bout=new ByteArrayOutputStream();
  GZIPOutputStream gzipStream=new GZIPOutputStream(bout);
  gzipStream.write(src);
  gzipStream.flush();
  gzipStream.close();
  bout.flush();
  return bout.toByteArray();
}
 

Example 26

From project ardverk-commons, under directory /src/main/java/org/ardverk/io/.

Source file: GzipCompressor.java

  31 
vote

@Override public byte[] compress(byte[] value,int offset,int length) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream(MathUtils.nextPowOfTwo(length));
  try (OutputStream out=new GZIPOutputStream(baos)){
    out.write(value,offset,length);
  }
  finally {
    IoUtils.close(baos);
  }
  return baos.toByteArray();
}
 

Example 27

From project Arecibo, under directory /util/src/main/java/com/ning/arecibo/util/.

Source file: ZipUtils.java

  31 
vote

public static byte[] gzip(byte[] input) throws IOException {
  ByteArrayOutputStream o=out.get();
  o.reset();
  GZIPOutputStream z=null;
  try {
    z=new GZIPOutputStream(o);
    z.write(input);
    z.finish();
    z.flush();
  }
  finally {
    if (z != null) {
      z.close();
    }
  }
  return o.toByteArray();
}
 

Example 28

From project Baseform-Epanet-Java-Library, under directory /src/org/addition/epanet/network/io/output/.

Source file: XMLComposer.java

  31 
vote

@Override public void composer(Network net,File f) throws ENException {
  XStream xStream=XMLParser.X_STREAM;
  try {
    OutputStream os=!gzip ? new FileOutputStream(f) : new GZIPOutputStream(new FileOutputStream(f));
    Writer w=new OutputStreamWriter(os,"UTF-8");
    xStream.toXML(net,w);
    w.close();
    os.close();
  }
 catch (  IOException e) {
    e.printStackTrace();
    throw new ENException(308);
  }
}
 

Example 29

From project cider, under directory /src/net/yacy/cider/util/.

Source file: FileUtils.java

  31 
vote

public static byte[] readAndZip(final File source) throws IOException {
  ByteArrayOutputStream byteOut=null;
  GZIPOutputStream zipOut=null;
  try {
    byteOut=new ByteArrayOutputStream((int)(source.length() / 2));
    zipOut=new GZIPOutputStream(byteOut);
    copy(source,zipOut);
    zipOut.close();
    return byteOut.toByteArray();
  }
  finally {
    if (zipOut != null)     try {
      zipOut.close();
    }
 catch (    final Exception e) {
    }
    if (byteOut != null)     try {
      byteOut.close();
    }
 catch (    final Exception e) {
    }
  }
}
 

Example 30

From project cloudhopper-commons-util, under directory /src/main/java/com/cloudhopper/commons/util/.

Source file: CompressionUtil.java

  31 
vote

@Override public void compress(File srcFile,File destFile) throws IOException {
  FileInputStream in=null;
  GZIPOutputStream out=null;
  try {
    in=new FileInputStream(srcFile);
    out=new GZIPOutputStream(new FileOutputStream(destFile));
    byte[] buf=new byte[1024];
    int len;
    while ((len=in.read(buf)) > 0) {
      out.write(buf,0,len);
    }
    in.close();
    in=null;
    out.finish();
    out.close();
    out=null;
  }
  finally {
    if (in != null) {
      try {
        in.close();
      }
 catch (      Exception e) {
      }
    }
    if (out != null) {
      logger.warn("Output stream for GZIP compressed file was not null -- indicates error with compression occurred");
      try {
        out.close();
      }
 catch (      Exception e) {
      }
    }
  }
}
 

Example 31

From project core_1, under directory /runtime/src/main/java/org/switchyard/internal/io/.

Source file: GZIPSerializer.java

  31 
vote

/** 
 * {@inheritDoc}
 */
@Override public <T>int serialize(T obj,Class<T> type,OutputStream out,int bufferSize) throws IOException {
  out=new CountingOutputStream(out);
  GZIPOutputStream gzip=new GZIPOutputStream(out,bufferSize);
  try {
    _serializer.serialize(obj,type,gzip,bufferSize);
    gzip.finish();
    gzip.flush();
  }
  finally {
    if (isCloseEnabled()) {
      gzip.close();
    }
  }
  return ((CountingOutputStream)out).getCount();
}
 

Example 32

From project eucalyptus, under directory /clc/modules/storage-controller/src/edu/ucsb/eucalyptus/cloud/ws/.

Source file: Storage.java

  31 
vote

@Override protected boolean writeRequestBody(HttpState state,HttpConnection conn) throws IOException {
  if (null != getRequestHeader("expect") && getStatusCode() != HttpStatus.SC_CONTINUE) {
    return false;
  }
  InputStream inputStream;
  if (outFile != null) {
    inputStream=new FileInputStream(outFile);
    GZIPOutputStream gzipOutStream=new GZIPOutputStream(conn.getRequestOutputStream());
    byte[] buffer=new byte[StorageProperties.TRANSFER_CHUNK_SIZE];
    int bytesRead;
    int numberProcessed=0;
    long totalBytesProcessed=0;
    while ((bytesRead=inputStream.read(buffer)) > 0) {
      gzipOutStream.write(buffer,0,bytesRead);
      totalBytesProcessed+=bytesRead;
      if (++numberProcessed >= callback.getUpdateThreshold()) {
        callback.run();
        numberProcessed=0;
      }
    }
    if (totalBytesProcessed == outFile.length()) {
      callback.finish();
    }
 else {
      callback.failed();
    }
    gzipOutStream.flush();
    gzipOutStream.finish();
    inputStream.close();
    if (deleteOnXfer) {
      snapshotStorageManager.deleteAbsoluteObject(outFile.getAbsolutePath());
    }
  }
 else {
    return false;
  }
  return true;
}
 

Example 33

From project flume_1, under directory /flume-core/src/main/java/com/cloudera/flume/handlers/batch/.

Source file: GzipDecorator.java

  31 
vote

@Override public void append(Event e) throws IOException, InterruptedException {
  WriteableEvent we=new WriteableEvent(e);
  byte[] bs=we.toBytes();
  eventSize.addAndGet(bs.length);
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  GZIPOutputStream gzos=new GZIPOutputStream(baos);
  gzos.write(bs);
  gzos.close();
  Event gze=new EventImpl(new byte[0]);
  byte[] compressed=baos.toByteArray();
  gze.set(GunzipDecorator.GZDOC,compressed);
  super.append(gze);
  gzipSize.addAndGet(compressed.length);
  eventCount.incrementAndGet();
}
 

Example 34

From project formic, under directory /src/java/org/apache/tools/ant/taskdefs/.

Source file: Tar.java

  31 
vote

/** 
 * This method wraps the output stream with the corresponding compression method
 * @param ostream output stream
 * @return output stream with on-the-fly compression
 * @exception IOException thrown if file is not writable
 */
private OutputStream compress(final OutputStream ostream) throws IOException {
  final String v=getValue();
  if (GZIP.equals(v)) {
    return new GZIPOutputStream(ostream);
  }
 else {
    if (BZIP2.equals(v)) {
      ostream.write('B');
      ostream.write('Z');
      return new CBZip2OutputStream(ostream);
    }
  }
  return ostream;
}
 

Example 35

From project git-starteam, under directory /fake-starteam/src/org/ossnoize/fakestarteam/.

Source file: SimpleTypedResourceIDProvider.java

  31 
vote

private void saveNewID(){
  GZIPOutputStream gzout=null;
  ObjectOutputStream out=null;
  try {
    File rootDir=InternalPropertiesProvider.getInstance().getFile();
    File path=new File(rootDir.getCanonicalPath() + File.separator + resourceIDFile);
    gzout=new GZIPOutputStream(new FileOutputStream(path));
    out=new ObjectOutputStream(gzout);
    out.writeObject(this);
    System.out.println("Saved " + assignedResourceID.size() + " ressource ID");
  }
 catch (  IOException ie) {
    ie.printStackTrace();
  }
 finally {
    FileUtility.close(gzout,out);
  }
}
 

Example 36

From project hank, under directory /src/java/com/rapleaf/hank/compress/.

Source file: JavaGzipCompressionCodec.java

  31 
vote

@Override public int compress(byte[] src,int srcOffset,int srcLength,byte[] dst,int dstOff){
  if (srcLength - srcOffset == 0) {
    return 0;
  }
  try {
    ByteArrayOutputStream bytesOut=new ByteArrayOutputStream(srcLength - srcOffset);
    GZIPOutputStream gzip=new GZIPOutputStream(bytesOut);
    gzip.write(src,srcOffset,srcLength);
    gzip.flush();
    gzip.close();
    byte[] compressed=bytesOut.toByteArray();
    System.arraycopy(compressed,0,dst,dstOff,compressed.length);
    return compressed.length;
  }
 catch (  IOException e) {
    throw new RuntimeException("Unexpected IOException while compressing!",e);
  }
}
 

Example 37

From project ihtika, under directory /Incubator/ForInstaller/PackLibs/src/com/google/code/ihtika/IhtikaClient/packlibs/.

Source file: GZip.java

  31 
vote

/** 
 * ?????? ??????? ???? data ? ?????????? ? toFileName
 * @param data - ?????? ????, ??????????????? ??? ??????
 * @param toFileName - ???? ? ????? , ? ??????? ?????????
 */
public void gzipArray(byte[] data,String toFileName) throws Exception {
  OutputStream out=new GZIPOutputStream(new FileOutputStream(toFileName));
  out.write(data);
  out.flush();
  out.close();
}
 

Example 38

From project indextank-engine, under directory /flaptor-util/com/flaptor/util/.

Source file: IOUtil.java

  31 
vote

public static void serialize(Object o,OutputStream os,boolean compress) throws IOException {
  GZIPOutputStream gos=null;
  ObjectOutputStream oos=null;
  try {
    if (compress) {
      gos=new GZIPOutputStream(os);
      os=gos;
    }
    oos=new ObjectOutputStream(os);
    oos.writeObject(o);
    oos.flush();
    if (gos != null) {
      gos.flush();
    }
  }
  finally {
    Execute.close(oos,logger);
    Execute.close(gos,logger);
  }
}
 

Example 39

From project iudex_1, under directory /iudex-barc/src/main/java/iudex/barc/.

Source file: BARCFile.java

  31 
vote

private void openOutputStream() throws IOException {
  if (_out == null) {
    _out=new RecordOutputStream();
    if (_compressed) {
      _out=new GZIPOutputStream(_out,BUFFER_SIZE);
    }
  }
}
 

Example 40

From project Ivory_1, under directory /src/java/main/ivory/core/util/.

Source file: ResultWriter.java

  31 
vote

/** 
 * @param file
 * @param compress
 * @throws IOException
 */
public ResultWriter(String file,boolean compress,FileSystem fs) throws IOException {
  FSDataOutputStream out=fs.create(new Path(file),true);
  if (compress) {
    gzipStream=new GZIPOutputStream(out);
    writer=new OutputStreamWriter(gzipStream);
  }
 else {
    writer=new BufferedWriter(new OutputStreamWriter(out),OUTPUT_BUFFER_SIZE);
  }
}
 

Example 41

From project jetty-session-redis, under directory /src/main/java/com/ovea/jetty/session/serializer/.

Source file: BinarySerializer.java

  31 
vote

@Override public final String serialize(Object o){
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    if (gzip) {
      GZIPOutputStream gout=new GZIPOutputStream(baos);
      write(gout,o);
      gout.finish();
      gout.close();
    }
 else {
      write(baos,o);
    }
    return String.valueOf(B64Code.encode(baos.toByteArray(),false));
  }
 catch (  Exception e) {
    throw new SerializerException("Error serializing " + o + " : "+ e.getMessage(),e);
  }
}
 

Example 42

From project jmd, under directory /src/org/apache/bcel/classfile/.

Source file: Utility.java

  31 
vote

/** 
 * Encode byte array it into Java identifier string, i.e., a string that only contains the following characters: (a, ... z, A, ... Z, 0, ... 9, _, $).  The encoding algorithm itself is not too clever: if the current byte's ASCII value already is a valid Java identifier part, leave it as it is. Otherwise it writes the escape character($) followed by <p><ul><li> the ASCII value as a hexadecimal string, if the value is not in the range 200..247</li> <li>a Java identifier char not used in a lowercase hexadecimal string, if the value is in the range 200..247</li><ul></p> <p>This operation inflates the original byte array by roughly 40-50%</p>
 * @param bytes the byte array to convert
 * @param compress use gzip to minimize string
 */
public static String encode(byte[] bytes,boolean compress) throws IOException {
  if (compress) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    GZIPOutputStream gos=new GZIPOutputStream(baos);
    gos.write(bytes,0,bytes.length);
    gos.close();
    baos.close();
    bytes=baos.toByteArray();
  }
  CharArrayWriter caw=new CharArrayWriter();
  JavaWriter jw=new JavaWriter(caw);
  for (int i=0; i < bytes.length; i++) {
    int in=bytes[i] & 0x000000ff;
    jw.write(in);
  }
  return caw.toString();
}
 

Example 43

From project joshua, under directory /src/joshua/pro/.

Source file: PROCore.java

  31 
vote

private void gzipFile(String inputFileName,String gzippedFileName){
  try {
    FileInputStream in=new FileInputStream(inputFileName);
    GZIPOutputStream out=new GZIPOutputStream(new FileOutputStream(gzippedFileName));
    byte[] buffer=new byte[4096];
    int len;
    while ((len=in.read(buffer)) > 0) {
      out.write(buffer,0,len);
    }
    in.close();
    out.finish();
    out.close();
    deleteFile(inputFileName);
  }
 catch (  IOException e) {
    System.err.println("IOException in PROCore.gzipFile(String,String): " + e.getMessage());
    System.exit(99902);
  }
}
 

Example 44

From project JoSQL, under directory /src/main/java/com/gentlyweb/utils/.

Source file: IOUtils.java

  31 
vote

/** 
 * GZIP a file, this will move the file from the given name to the new location.  This leaves the old file in place!
 * @param file The existing file name of the file.
 * @param newFile The new file location for the file.
 * @throws ChainException If we can't perform the transfer, the inner exception willcontain an IOException that is the "real" exception.
 */
public static void gzipFile(File file,File newFile) throws ChainException {
  try {
    BufferedInputStream oldFileRead=new BufferedInputStream(new FileInputStream(file));
    GZIPOutputStream gzout=new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(newFile)));
    try {
      byte[] buf=new byte[4096];
      IOUtils.streamTo(oldFileRead,gzout,4096);
    }
 catch (    IOException e) {
      throw new ChainException("Unable to gzip file: " + file.getPath() + " to: "+ newFile.getPath(),e);
    }
 finally {
      if (oldFileRead != null) {
        oldFileRead.close();
      }
      if (gzout != null) {
        gzout.flush();
        gzout.close();
      }
    }
  }
 catch (  IOException e) {
    throw new ChainException("Unable to gzip file: " + file.getPath() + " to: "+ newFile.getPath(),e);
  }
}
 

Example 45

From project Kairos, under directory /src/java/org/apache/nutch/util/.

Source file: GZIPUtils.java

  31 
vote

/** 
 * Returns an gzipped copy of the input array.
 */
public static final byte[] zip(byte[] in){
  try {
    ByteArrayOutputStream byteOut=new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO);
    GZIPOutputStream outStream=new GZIPOutputStream(byteOut);
    try {
      outStream.write(in);
    }
 catch (    Exception e) {
      e.printStackTrace(LogUtil.getWarnStream(LOG));
    }
    try {
      outStream.close();
    }
 catch (    IOException e) {
      e.printStackTrace(LogUtil.getWarnStream(LOG));
    }
    return byteOut.toByteArray();
  }
 catch (  IOException e) {
    e.printStackTrace(LogUtil.getWarnStream(LOG));
    return null;
  }
}
 

Example 46

From project karaf, under directory /webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/.

Source file: GogoPlugin.java

  31 
vote

@Override protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
  String encoding=request.getHeader("Accept-Encoding");
  boolean supportsGzip=(encoding != null && encoding.toLowerCase().indexOf("gzip") > -1);
  SessionTerminal st=(SessionTerminal)request.getSession(true).getAttribute("terminal");
  if (st == null || st.isClosed()) {
    st=new SessionTerminal();
    request.getSession().setAttribute("terminal",st);
  }
  String str=request.getParameter("k");
  String f=request.getParameter("f");
  String dump=st.handle(str,f != null && f.length() > 0);
  if (dump != null) {
    if (supportsGzip) {
      response.setHeader("Content-Encoding","gzip");
      response.setHeader("Content-Type","text/html");
      try {
        GZIPOutputStream gzos=new GZIPOutputStream(response.getOutputStream());
        gzos.write(dump.getBytes());
        gzos.close();
      }
 catch (      IOException ie) {
        ie.printStackTrace();
      }
    }
 else {
      response.getOutputStream().write(dump.getBytes());
    }
  }
}
 

Example 47

From project Kayak, under directory /Kayak-logging/src/main/java/com/github/kayak/logging/.

Source file: CompressLogFileAction.java

  31 
vote

@Override public void actionPerformed(ActionEvent e){
  if (lf != null && !lf.getCompressed()) {
    File f=lf.getFile();
    try {
      File newFile=new File(f.getAbsolutePath() + ".gz");
      GZIPOutputStream out=new GZIPOutputStream(new FileOutputStream(newFile));
      FileInputStream in=new FileInputStream(f);
      byte[] buf=new byte[1024];
      int len;
      while ((len=in.read(buf)) > 0) {
        out.write(buf,0,len);
      }
      in.close();
      out.finish();
      out.close();
      f.delete();
      LogFileManager.getGlobalLogFileManager().removeLogFile(lf);
      LogFileManager.getGlobalLogFileManager().addLogFile(new LogFile(newFile));
    }
 catch (    IOException ex) {
      logger.log(Level.WARNING,"Could not compress log file",ex);
    }
  }
}
 

Example 48

From project kevoree-library, under directory /javase/org.kevoree.library.javase.webserver.aceEditor/src/main/java/com/google/gwt/user/server/rpc/.

Source file: RPCServletUtils.java

  31 
vote

/** 
 * Write the response content into the  {@link HttpServletResponse}. If <code>gzipResponse</code> is <code>true</code>, the response content will be gzipped prior to being written into the response.
 * @param servletContext servlet context for this response
 * @param response response instance
 * @param responseContent a string containing the response content
 * @param gzipResponse if <code>true</code> the response content will be gzipencoded before being written into the response
 * @throws IOException if reading, writing, or closing the response's outputstream fails
 */
public static void writeResponse(ServletContext servletContext,HttpServletResponse response,String responseContent,boolean gzipResponse) throws IOException {
  byte[] responseBytes=responseContent.getBytes(CHARSET_UTF8);
  if (gzipResponse) {
    ByteArrayOutputStream output=null;
    GZIPOutputStream gzipOutputStream=null;
    Throwable caught=null;
    try {
      output=new ByteArrayOutputStream(responseBytes.length);
      gzipOutputStream=new GZIPOutputStream(output);
      gzipOutputStream.write(responseBytes);
      gzipOutputStream.finish();
      gzipOutputStream.flush();
      setGzipEncodingHeader(response);
      responseBytes=output.toByteArray();
    }
 catch (    IOException e) {
      caught=e;
    }
 finally {
      if (null != gzipOutputStream) {
        gzipOutputStream.close();
      }
      if (null != output) {
        output.close();
      }
    }
    if (caught != null) {
      servletContext.log("Unable to compress response",caught);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }
  }
  response.setContentLength(responseBytes.length);
  response.setContentType(CONTENT_TYPE_APPLICATION_JSON_UTF8);
  response.setStatus(HttpServletResponse.SC_OK);
  response.setHeader(CONTENT_DISPOSITION,ATTACHMENT);
  response.getOutputStream().write(responseBytes);
}
 

Example 49

From project kwegg, under directory /lib/readwrite/opennlp-tools/src/java/opennlp/tools/dictionary/serializer/.

Source file: DictionarySerializer.java

  31 
vote

/** 
 * Serializes the given entries to the given  {@link OutputStream}.
 * @param out 
 * @param entries 
 * @throws IOException If an I/O error occurs
 */
public static void serialize(OutputStream out,Iterator entries) throws IOException {
  GZIPOutputStream gzipOut=new GZIPOutputStream(out);
  StreamResult streamResult=new StreamResult(gzipOut);
  SAXTransformerFactory tf=(SAXTransformerFactory)SAXTransformerFactory.newInstance();
  TransformerHandler hd;
  try {
    hd=tf.newTransformerHandler();
  }
 catch (  TransformerConfigurationException e1) {
    throw new AssertionError("The Tranformer configuration must be valid!");
  }
  Transformer serializer=hd.getTransformer();
  serializer.setOutputProperty(OutputKeys.ENCODING,CHARSET);
  serializer.setOutputProperty(OutputKeys.INDENT,"yes");
  hd.setResult(streamResult);
  try {
    hd.startDocument();
    hd.startElement("","",DICTIONARY_ELEMENT,new AttributesImpl());
    while (entries.hasNext()) {
      Entry entry=(Entry)entries.next();
      serializeEntry(hd,entry);
    }
    hd.endElement("","",DICTIONARY_ELEMENT);
    hd.endDocument();
  }
 catch (  SAXException e) {
    throw new IOException("There was an error during serialization!");
  }
  gzipOut.finish();
}
 

Example 50

From project litle-sdk-for-java, under directory /lib/apache-cxf-2.5.2/samples/configuration_interceptor/src/main/java/demo/stream/interceptor/.

Source file: StreamInterceptor.java

  31 
vote

public void handleMessage(Message message){
  boolean isOutbound=false;
  isOutbound=message == message.getExchange().getOutMessage() || message == message.getExchange().getOutFaultMessage();
  if (isOutbound) {
    OutputStream os=message.getContent(OutputStream.class);
    CachedStream cs=new CachedStream();
    message.setContent(OutputStream.class,cs);
    message.getInterceptorChain().doIntercept(message);
    try {
      cs.flush();
      CachedOutputStream csnew=(CachedOutputStream)message.getContent(OutputStream.class);
      GZIPOutputStream zipOutput=new GZIPOutputStream(os);
      CachedOutputStream.copyStream(csnew.getInputStream(),zipOutput,1024);
      cs.close();
      zipOutput.close();
      os.flush();
      message.setContent(OutputStream.class,os);
    }
 catch (    IOException ioe) {
      ioe.printStackTrace();
    }
  }
 else {
    try {
      InputStream is=message.getContent(InputStream.class);
      GZIPInputStream zipInput=new GZIPInputStream(is);
      message.setContent(InputStream.class,zipInput);
    }
 catch (    IOException ioe) {
      ioe.printStackTrace();
    }
  }
}
 

Example 51

From project morphia, under directory /morphia/src/main/java/com/google/code/morphia/mapping/.

Source file: Serializer.java

  31 
vote

/** 
 * serializes object to byte[] 
 */
public static byte[] serialize(final Object o,final boolean zip) throws IOException {
  final ByteArrayOutputStream baos=new ByteArrayOutputStream();
  OutputStream os=baos;
  if (zip) {
    os=new GZIPOutputStream(os);
  }
  final ObjectOutputStream oos=new ObjectOutputStream(os);
  oos.writeObject(o);
  oos.flush();
  oos.close();
  return baos.toByteArray();
}
 

Example 52

From project nutch, under directory /src/java/org/apache/nutch/util/.

Source file: GZIPUtils.java

  31 
vote

/** 
 * Returns an gzipped copy of the input array.
 */
public static final byte[] zip(byte[] in){
  try {
    ByteArrayOutputStream byteOut=new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO);
    GZIPOutputStream outStream=new GZIPOutputStream(byteOut);
    try {
      outStream.write(in);
    }
 catch (    Exception e) {
      LOG.error("Error writing outStream: ",e);
    }
    try {
      outStream.close();
    }
 catch (    IOException e) {
      LOG.error("Error closing outStream: ",e);
    }
    return byteOut.toByteArray();
  }
 catch (  IOException e) {
    LOG.error("Error: ",e);
    return null;
  }
}
 

Example 53

From project OWASP-WebScarab, under directory /src/org/owasp/webscarab/model/.

Source file: Message.java

  31 
vote

/** 
 * Sets the content of the message body. If the message headers indicate that the content is gzipped, the content is automatically compressed
 * @param bytes a byte array containing the message body
 */
public void setContent(byte[] bytes){
  try {
    flushContentStream(null);
  }
 catch (  IOException ioe) {
    _logger.info("IOException flushing the contentStream " + ioe);
  }
  if (_gzipped) {
    try {
      _content=new ByteArrayOutputStream();
      GZIPOutputStream gzos=new GZIPOutputStream(_content);
      gzos.write(bytes);
      gzos.close();
    }
 catch (    IOException ioe) {
      _logger.info("IOException gzipping content : " + ioe);
    }
  }
 else {
    _content=new ByteArrayOutputStream();
    try {
      if (bytes != null)       _content.write(bytes);
    }
 catch (    IOException ioe) {
    }
  }
  String cl=getHeader("Content-length");
  if (cl != null) {
    setHeader(new NamedValue("Content-length",Integer.toString(_content.size())));
  }
}
 

Example 54

From project plexus-archiver, under directory /src/main/java/org/codehaus/plexus/archiver/gzip/.

Source file: GZipCompressor.java

  31 
vote

/** 
 * perform the GZip compression operation.
 */
public void compress() throws ArchiverException {
  try {
    zOut=new GZIPOutputStream(new FileOutputStream(getDestFile()));
    compress(getSource(),zOut);
  }
 catch (  IOException ioe) {
    String msg="Problem creating gzip " + ioe.getMessage();
    throw new ArchiverException(msg,ioe);
  }
}
 

Example 55

From project rapidandroid, under directory /rapidandroid/org.rapidandroid/src/org/rapidandroid/data/controller/.

Source file: ParsedDataReporter.java

  31 
vote

void compressFile(File rawFile){
  FileInputStream fin=null;
  GZIPOutputStream gz=null;
  try {
    fin=new FileInputStream(rawFile);
    FileOutputStream fout=new FileOutputStream(rawFile.getAbsoluteFile() + ".gz");
    gz=new GZIPOutputStream(fout);
    byte[] buf=new byte[4096];
    int readCount;
    while ((readCount=fin.read(buf)) != -1) {
      gz.write(buf,0,readCount);
    }
  }
 catch (  Exception ex) {
  }
 finally {
    try {
      if (fin != null)       fin.close();
      if (gz != null)       gz.close();
    }
 catch (    IOException ex) {
      ex.printStackTrace();
    }
  }
}
 

Example 56

From project riot, under directory /cachius/src/org/riotfamily/cachius/http/content/.

Source file: GzipContent.java

  31 
vote

public GzipContent(File file,File zipFile) throws IOException {
  super(file);
  this.zipFile=zipFile;
  InputStream in=new BufferedInputStream(new FileInputStream(file));
  OutputStream out=new GZIPOutputStream(new FileOutputStream(zipFile));
  IOUtils.copy(in,out);
  IOUtils.closeStream(out);
}
 

Example 57

From project shrinkwrap, under directory /impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/tar/.

Source file: TarGzOutputStream.java

  31 
vote

public TarGzOutputStream(OutputStream out) throws IOException {
  super(null);
  this.gzip=new GZIPOutputStream(out);
  this.tos=new TarOutputStreamImpl(this.gzip);
  this.bos=new ByteArrayOutputStream();
}
 

Example 58

From project Siafu, under directory /Siafu/src/main/java/de/nec/nle/siafu/utils/.

Source file: PersistentCachedMap.java

  31 
vote

/** 
 * Store a mapping on the persisted storage, by writing it to a file.
 * @param key the key for the mapping
 * @param value the value for the mapping
 */
protected void persistObject(final Object key,final Object value){
  try {
    FileOutputStream fOut=new FileOutputStream(path + key + ".data");
    GZIPOutputStream gzFOut=new GZIPOutputStream(fOut);
    ObjectOutputStream objOut=new ObjectOutputStream(gzFOut);
    objOut.writeObject(value);
    gzFOut.finish();
    gzFOut.close();
    objOut.close();
  }
 catch (  Exception e) {
    e.printStackTrace();
    throw new RuntimeException("Can't write " + path + value+ ".data");
  }
}
 

Example 59

From project Solbase, under directory /src/org/solbase/cache/.

Source file: VersionedCache.java

  31 
vote

protected static final byte[] compress(byte[] in){
  if (in == null) {
    throw new NullPointerException("Can't compress null");
  }
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  GZIPOutputStream gz=null;
  try {
    gz=new GZIPOutputStream(bos);
    gz.write(in);
  }
 catch (  IOException e) {
    throw new RuntimeException("IO exception compressing data",e);
  }
 finally {
    if (gz != null) {
      try {
        gz.close();
      }
 catch (      IOException e) {
        log.error("Close GZIPOutputStream error",e);
      }
    }
    if (bos != null) {
      try {
        bos.close();
      }
 catch (      IOException e) {
        log.error("Close ByteArrayOutputStream error",e);
      }
    }
  }
  byte[] rv=bos.toByteArray();
  return rv;
}
 

Example 60

From project spring-android, under directory /spring-android-rest-template/src/main/java/org/springframework/http/client/.

Source file: AbstractClientHttpRequest.java

  31 
vote

private OutputStream getCompressedBody(OutputStream body) throws IOException {
  if (this.compressedBody == null) {
    this.compressedBody=new GZIPOutputStream(body);
  }
  return this.compressedBody;
}
 

Example 61

From project sulky, under directory /sulky-buffers/src/main/java/de/huxhorn/sulky/buffers/.

Source file: SerializingFileBuffer.java

  31 
vote

private int internalWriteElement(RandomAccessFile randomSerializeFile,long offset,E element) throws IOException {
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  GZIPOutputStream gos=new GZIPOutputStream(bos);
  ObjectOutputStream out=new ObjectOutputStream(gos);
  out.writeObject(element);
  out.flush();
  out.close();
  gos.finish();
  byte[] buffer=bos.toByteArray();
  int bufferSize=buffer.length;
  randomSerializeFile.seek(offset);
  randomSerializeFile.writeInt(bufferSize);
  randomSerializeFile.write(buffer);
  return bufferSize;
}
 

Example 62

From project td-client-java, under directory /src/test/java/com/treasure_data/client/.

Source file: TestDeletePartialTable.java

  31 
vote

private void importData(DefaultClientAdaptorImpl clientAdaptor,String databaseName,String tableName) throws Exception {
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  GZIPOutputStream gzout=new GZIPOutputStream(out);
  MessagePack msgpack=new MessagePack();
  Packer packer=msgpack.createPacker(gzout);
  long baseTime=1337000400;
  for (int i=0; i < 500; i++) {
    long time=baseTime + 3600 * i;
    Map<String,Object> record=new HashMap<String,Object>();
    record.put("name","muga:" + i);
    record.put("id",i);
    record.put("time",time);
    packer.write(record);
  }
  gzout.finish();
  byte[] bytes=out.toByteArray();
  ImportRequest request=new ImportRequest(new Table(new Database(databaseName),tableName),bytes);
  ImportResult result=clientAdaptor.importData(request);
}
 

Example 63

From project tdbloader4, under directory /src/main/java/org/apache/jena/tdbloader4/.

Source file: FourthReducer.java

  31 
vote

private OutputStream getOutputStream(String filename) throws IOException {
  OutputStream output=null;
  if (!outputs.containsKey(filename)) {
    output=new GZIPOutputStream(new FileOutputStream(outLocal.toString() + "/" + filename+ "_"+ taskAttemptID+ ".gz"));
    outputs.put(filename,output);
  }
  return outputs.get(filename);
}
 

Example 64

From project teatrove, under directory /trove/src/main/java/org/teatrove/trove/util/.

Source file: ClassInjector.java

  31 
vote

protected void define(String name,byte[] data){
  defineClass(name,data,0,data.length);
  if (mGZippedBytecode != null) {
    try {
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      GZIPOutputStream gz=new GZIPOutputStream(baos);
      gz.write(data,0,data.length);
      gz.close();
      mGZippedBytecode.put(name.replace('.','/') + ".class",baos.toByteArray());
    }
 catch (    IOException ioe) {
      ioe.printStackTrace();
    }
  }
}
 

Example 65

From project Terasology, under directory /src/main/java/org/terasology/world/chunks/store/.

Source file: ChunkStoreGZip.java

  31 
vote

private void saveChunk(Chunk c){
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    GZIPOutputStream gzipOut=new GZIPOutputStream(baos);
    ObjectOutputStream objectOut=new ObjectOutputStream(gzipOut);
    objectOut.writeObject(c);
    objectOut.close();
    byte[] b=baos.toByteArray();
    sizeInByte.addAndGet(b.length);
    compressedChunks.put(c.getPos(),b);
    modifiedChunks.remove(c.getPos(),c);
  }
 catch (  IOException e) {
    logger.error("Error saving chunk",e);
  }
}
 

Example 66

From project v7files, under directory /src/main/java/v7db/files/.

Source file: Compression.java

  31 
vote

/** 
 * @return null, if the "gzipped" data is larger than the input (or therehas been an exception)
 */
public static byte[] gzip(byte[] data,int off,int len){
  if (len < GZIP_STORAGE_OVERHEAD)   return null;
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream(data.length);
    GZIPOutputStream gz=new GZIPOutputStream(baos);
    gz.write(data,off,len);
    gz.close();
    if (baos.size() >= len)     return null;
    return baos.toByteArray();
  }
 catch (  Exception e) {
    log.error("failed to gzip byte array",e);
    return null;
  }
}
 

Example 67

From project vanilla, under directory /src/main/java/org/spout/vanilla/resources/.

Source file: MapPalette.java

  31 
vote

/** 
 * Tries to save this Map Palette to file
 * @param file to save to
 * @return True if it was successful, False if not
 */
public boolean save(File file){
  try {
    GZIPOutputStream stream=new GZIPOutputStream(new FileOutputStream(file));
    try {
      this.write(stream);
      return true;
    }
  finally {
      stream.close();
    }
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
  return false;
}
 

Example 68

From project virgo.apps, under directory /org.eclipse.virgo.apps.splash/src/main/java/org/eclipse/virgo/apps/splash/.

Source file: GZIPResponseStream.java

  31 
vote

public GZIPResponseStream(HttpServletResponse response) throws IOException {
  super();
  closed=false;
  this.response=response;
  this.servletStream=response.getOutputStream();
  byteStream=new ByteArrayOutputStream();
  gzipStream=new GZIPOutputStream(byteStream);
}
 

Example 69

From project virgo.kernel, under directory /org.eclipse.virgo.management.console/src/main/java/org/eclipse/virgo/management/console/internal/.

Source file: GZIPResponseStream.java

  31 
vote

public GZIPResponseStream(HttpServletResponse response) throws IOException {
  super();
  closed=false;
  this.response=response;
  this.servletStream=response.getOutputStream();
  byteStream=new ByteArrayOutputStream();
  gzipStream=new GZIPOutputStream(byteStream);
}
 

Example 70

From project wagon-ahc, under directory /src/test/java/org/sonatype/maven/wagon/providers/http/.

Source file: HttpWagonTestCase.java

  31 
vote

private String writeTestFileGzip(final File parent,final String child) throws IOException {
  File file=new File(parent,child);
  file.getParentFile().mkdirs();
  OutputStream out=new FileOutputStream(file);
  out.write(child.getBytes());
  out.close();
  file=new File(parent,child + ".gz");
  out=new FileOutputStream(file);
  out=new GZIPOutputStream(out);
  String content=file.getAbsolutePath();
  out.write(content.getBytes());
  out.close();
  return content;
}
 

Example 71

From project WCF-Package-Builder, under directory /src/com/wainox/io/tar/.

Source file: TarWriter.java

  31 
vote

@Override public void close() throws IOException {
  super.close();
  this.output.close();
  if (this.compressed) {
    GZIPOutputStream output=new GZIPOutputStream(new FileOutputStream(this.archive));
    FileInputStream input=new FileInputStream(this.uncompressedArchive);
    byte[] buffer=new byte[1024];
    int length;
    while ((length=input.read(buffer)) > 0) {
      output.write(buffer,0,length);
    }
    input.close();
    output.finish();
    output.close();
  }
}
 

Example 72

From project xmemcached, under directory /src/main/java/net/rubyeye/xmemcached/transcoders/.

Source file: BaseSerializingTranscoder.java

  31 
vote

private static byte[] gzipCompress(byte[] in){
  if (in == null) {
    throw new NullPointerException("Can't compress null");
  }
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  GZIPOutputStream gz=null;
  try {
    gz=new GZIPOutputStream(bos);
    gz.write(in);
  }
 catch (  IOException e) {
    throw new RuntimeException("IO exception compressing data",e);
  }
 finally {
    if (gz != null) {
      try {
        gz.close();
      }
 catch (      IOException e) {
        log.error("Close GZIPOutputStream error",e);
      }
    }
    if (bos != null) {
      try {
        bos.close();
      }
 catch (      IOException e) {
        log.error("Close ByteArrayOutputStream error",e);
      }
    }
  }
  byte[] rv=bos.toByteArray();
  return rv;
}
 

Example 73

From project agraph-java-client, under directory /src/test/.

Source file: Util.java

  30 
vote

public static void gzip(File in,File out) throws IOException {
  FileInputStream is=null;
  OutputStream os=null;
  try {
    is=new FileInputStream(in);
    os=new GZIPOutputStream(new FileOutputStream(out));
    for (int ch=is.read(); ch != -1; ch=is.read()) {
      os.write(ch);
    }
    os.flush();
  }
  finally {
    Closer.Close(is);
    Closer.Close(os);
  }
}
 

Example 74

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/servlet/filter/.

Source file: AbstractGZIPFilter.java

  30 
vote

/** 
 * Creates output stream with GZIP delegation.
 * @return servlet output stream
 * @throws IOException io exception
 */
private ServletOutputStream createOutputStream() throws IOException {
  final ServletResponse servletResponse=this.getResponse();
  gzipStream=new GZIPOutputStream(servletResponse.getOutputStream());
  return new ServletOutputStream(){
    @Override public void write(    final int b) throws IOException {
      gzipStream.write(b);
    }
    @Override public void flush() throws IOException {
      gzipStream.flush();
    }
    @Override public void close() throws IOException {
      gzipStream.close();
    }
    @Override public void write(    final byte[] b) throws IOException {
      gzipStream.write(b);
    }
    @Override public void write(    final byte[] b,    final int off,    final int len) throws IOException {
      gzipStream.write(b,off,len);
    }
  }
;
}
 

Example 75

From project Cours-3eme-ann-e, under directory /Java/tomcat/examples/WEB-INF/classes/compressionFilters/.

Source file: CompressionResponseStream.java

  30 
vote

public void writeToGZip(byte b[],int off,int len) throws IOException {
  if (debug > 1) {
    System.out.println("writeToGZip, len = " + len);
  }
  if (debug > 2) {
    System.out.print("writeToGZip(");
    System.out.write(b,off,len);
    System.out.println(")");
  }
  if (gzipstream == null) {
    if (debug > 1) {
      System.out.println("new GZIPOutputStream");
    }
    if (response.isCommitted()) {
      if (debug > 1)       System.out.print("Response already committed. Using original output stream");
      gzipstream=output;
    }
 else {
      response.addHeader("Content-Encoding","gzip");
      gzipstream=new GZIPOutputStream(output);
    }
  }
  gzipstream.write(b,off,len);
}
 

Example 76

From project hdiv, under directory /hdiv-core/src/main/java/org/hdiv/util/.

Source file: EncodingUtil.java

  30 
vote

/** 
 * The object <code>obj</code> is compressed, encrypted and coded in Base64.
 * @param obj Object to encrypt
 * @return Objet <code>obj</code> compressed, encrypted and coded in Base64
 * @throws HDIVException if there is an error encoding object <code>data</code>
 * @see java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream)
 * @see org.apache.commons.codec.net.URLCodec#encodeUrl(java.util.BitSet,byte[])
 * @see org.apache.commons.codec.binary.Base64#encode(byte[])
 */
public String encode64Cipher(Object obj){
  try {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    OutputStream zos=new GZIPOutputStream(baos);
    ObjectOutputStream oos=new ObjectOutputStream(zos);
    oos.writeObject(obj);
    oos.close();
    zos.close();
    baos.close();
    byte[] cipherData=this.session.getEncryptCipher().encrypt(baos.toByteArray());
    byte[] encodedData=URLCodec.encodeUrl(null,cipherData);
    Base64 base64Codec=new Base64();
    return new String(base64Codec.encode(encodedData),ZIP_CHARSET);
  }
 catch (  Exception e) {
    String errorMessage=HDIVUtil.getMessage("encode.message");
    throw new HDIVException(errorMessage,e);
  }
}
 

Example 77

From project http-testing-harness, under directory /server-provider/src/main/java/org/sonatype/tests/http/server/jetty/behaviour/.

Source file: ResourceServer.java

  30 
vote

public boolean execute(HttpServletRequest request,HttpServletResponse response,Map<Object,Object> ctx) throws Exception {
  String path=request.getPathInfo();
  logger.debug(request.getMethod() + " " + path);
  if ("GET".equals(request.getMethod())) {
    Resource res=db.get(path);
    if (res == null) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND,"Not Found");
      return false;
    }
    response.setContentLength(res.size);
    response.setContentType("application/octet-stream");
    copy(new GZIPInputStream(new ByteArrayInputStream(res.data)),response.getOutputStream());
  }
 else   if ("PUT".equals(request.getMethod())) {
    Resource res=new Resource();
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    res.size=copy(request.getInputStream(),new GZIPOutputStream(baos));
    res.data=baos.toByteArray();
    db.put(path,res);
  }
  return false;
}
 

Example 78

From project jena-fuseki, under directory /src/main/java/org/apache/jena/fuseki/mgt/.

Source file: ActionBackup.java

  30 
vote

public static void backup(DatasetGraph dsg,String backupfile){
  try {
    OutputStream out;
    if (false) {
      out=new FileOutputStream(backupfile + ".gz");
      out=new GZIPOutputStream(out,8 * 1024);
      out=new BufferedOutputStream(out);
    }
 else {
      out=new FileOutputStream(backupfile);
      out=new BufferedOutputStream(out);
    }
    NQuadsWriter.write(out,dsg);
    out.close();
  }
 catch (  FileNotFoundException e) {
    Log.warn(ActionBackup.class,"File not found: " + backupfile);
    throw new FusekiException("File not found: " + backupfile);
  }
catch (  IOException e) {
    IO.exception(e);
  }
}
 

Example 79

From project maven-wagon, under directory /wagon-provider-test/src/main/java/org/apache/maven/wagon/http/.

Source file: HttpWagonTestCase.java

  30 
vote

private String writeTestFileGzip(File parent,String child) throws IOException {
  File file=new File(parent,child);
  file.getParentFile().mkdirs();
  file.deleteOnExit();
  OutputStream out=new FileOutputStream(file);
  try {
    out.write(child.getBytes());
  }
  finally {
    out.close();
  }
  file=new File(parent,child + ".gz");
  file.deleteOnExit();
  String content;
  out=new FileOutputStream(file);
  out=new GZIPOutputStream(out);
  try {
    content=file.getAbsolutePath();
    out.write(content.getBytes());
  }
  finally {
    out.close();
  }
  return content;
}
 

Example 80

From project mawLib, under directory /src/mxj/trunk/mawLib-mxj/src/net/christopherbaker/xml/.

Source file: XMLElement.java

  30 
vote

/** 
 * I want to print lines to a file. I have RSI from typing these eight lines of code so many times.
 */
static public PrintWriter createWriter(File file){
  try {
    createPath(file);
    OutputStream output=new FileOutputStream(file);
    if (file.getName().toLowerCase().endsWith(".gz")) {
      output=new GZIPOutputStream(output);
    }
    return createWriter(output);
  }
 catch (  Exception e) {
    if (file == null) {
      throw new RuntimeException("File passed to createWriter() was null");
    }
 else {
      e.printStackTrace();
      throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath());
    }
  }
}
 

Example 81

From project ncDiamond, under directory /src/compressionFilters/.

Source file: CompressionResponseStream.java

  30 
vote

public void writeToGZip(byte b[],int off,int len) throws IOException {
  if (debug > 1) {
    System.out.println("writeToGZip, len = " + len);
  }
  if (debug > 2) {
    System.out.print("writeToGZip(");
    System.out.write(b,off,len);
    System.out.println(")");
  }
  if (gzipstream == null) {
    if (debug > 1) {
      System.out.println("new GZIPOutputStream");
    }
    response.addHeader("Content-Encoding","gzip");
    gzipstream=new GZIPOutputStream(output);
  }
  gzipstream.write(b,off,len);
}
 

Example 82

From project nuxeo-theme, under directory /nuxeo-theme-html/src/main/java/org/nuxeo/theme/html/servlets/.

Source file: Styles.java

  30 
vote

@Override protected void doPost(final HttpServletRequest request,final HttpServletResponse response) throws IOException {
  response.addHeader("content-type","text/css");
  final String themeName=request.getParameter("theme");
  if (themeName == null) {
    response.sendError(404);
    log.error("Theme name not set");
    return;
  }
  final String collectionName=request.getParameter("collection");
  ThemeDescriptor themeDescriptor=ThemeManager.getThemeDescriptorByThemeName(themeName);
  if (themeDescriptor == null) {
    throw new IOException("Theme not found: " + themeName);
  }
  if (!themeDescriptor.isLoaded()) {
    ThemeManager.loadTheme(themeDescriptor);
  }
  final String applicationPath=request.getParameter("path");
  if (applicationPath != null) {
    final ApplicationType application=(ApplicationType)Manager.getTypeRegistry().lookup(TypeFamily.APPLICATION,applicationPath);
    if (application != null) {
      Utils.setCacheHeaders(response,application.getStyleCaching());
    }
  }
  OutputStream os=response.getOutputStream();
  BufferingServletOutputStream.stopBuffering(os);
  if (Utils.supportsGzip(request)) {
    response.setHeader("Content-Encoding","gzip");
    response.setHeader("Vary","Accept-Encoding");
    os=new GZIPOutputStream(os);
  }
  final String basePath=request.getParameter("basepath");
  final ThemeManager themeManager=Manager.getThemeManager();
  String rendered=themeManager.getCachedStyles(themeName,basePath,collectionName);
  if (rendered == null) {
    rendered=ThemeStyles.generateThemeStyles(themeName,themeDescriptor,basePath,collectionName,true);
    themeManager.setCachedStyles(themeName,basePath,collectionName,rendered);
  }
  os.write(rendered.getBytes());
  os.close();
}
 

Example 83

From project ohmageServer, under directory /src/org/ohmage/request/.

Source file: Request.java

  30 
vote

/** 
 * There is functionality in Tomcat 6 to perform this action, but it is  also nice to have it controlled programmatically.
 * @return an OutputStream appropriate for the headers found in the request.
 */
protected OutputStream getOutputStream(HttpServletRequest request,HttpServletResponse response) throws IOException {
  OutputStream os=null;
  String encoding=request.getHeader("Accept-Encoding");
  if (encoding != null && encoding.indexOf("gzip") >= 0) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Returning a GZIPOutputStream");
    }
    response.setHeader("Content-Encoding","gzip");
    response.setHeader("Vary","Accept-Encoding");
    os=new GZIPOutputStream(response.getOutputStream());
  }
 else {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Returning the default OutputStream");
    }
    os=response.getOutputStream();
  }
  return os;
}
 

Example 84

From project Ohmage_Server_2, under directory /src/org/ohmage/request/.

Source file: Request.java

  30 
vote

/** 
 * There is functionality in Tomcat 6 to perform this action, but it is  also nice to have it controlled programmatically.
 * @return an OutputStream appropriate for the headers found in the request.
 */
protected OutputStream getOutputStream(HttpServletRequest request,HttpServletResponse response) throws IOException {
  OutputStream os=null;
  String encoding=request.getHeader("Accept-Encoding");
  if (encoding != null && encoding.indexOf("gzip") >= 0) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Returning a GZIPOutputStream");
    }
    response.setHeader("Content-Encoding","gzip");
    response.setHeader("Vary","Accept-Encoding");
    os=new GZIPOutputStream(response.getOutputStream());
  }
 else {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Returning the default OutputStream");
    }
    os=response.getOutputStream();
  }
  return os;
}
 

Example 85

From project opennlp, under directory /opennlp-maxent/src/main/java/opennlp/maxent/io/.

Source file: SuffixSensitiveGISModelWriter.java

  30 
vote

/** 
 * Constructor which takes a GISModel and a File and invokes the GISModelWriter appropriate for the suffix.
 * @param model The GISModel which is to be persisted.
 * @param f The File in which the model is to be stored.
 */
public SuffixSensitiveGISModelWriter(AbstractModel model,File f) throws IOException {
  super(model);
  OutputStream output;
  String filename=f.getName();
  if (filename.endsWith(".gz")) {
    output=new GZIPOutputStream(new FileOutputStream(f));
    filename=filename.substring(0,filename.length() - 3);
  }
 else {
    output=new DataOutputStream(new FileOutputStream(f));
  }
  if (filename.endsWith(".bin")) {
    suffixAppropriateWriter=new BinaryGISModelWriter(model,new DataOutputStream(output));
  }
 else {
    suffixAppropriateWriter=new PlainTextGISModelWriter(model,new BufferedWriter(new OutputStreamWriter(output)));
  }
}
 

Example 86

From project OpenNLP-Maxent-Joliciel, under directory /src/main/java/opennlp/maxent/io/.

Source file: SuffixSensitiveGISModelWriter.java

  30 
vote

/** 
 * Constructor which takes a GISModel and a File and invokes the GISModelWriter appropriate for the suffix.
 * @param model The GISModel which is to be persisted.
 * @param f The File in which the model is to be stored.
 */
public SuffixSensitiveGISModelWriter(AbstractModel model,File f) throws IOException {
  super(model);
  OutputStream output;
  String filename=f.getName();
  if (filename.endsWith(".gz")) {
    output=new GZIPOutputStream(new FileOutputStream(f));
    filename=filename.substring(0,filename.length() - 3);
  }
 else {
    output=new DataOutputStream(new FileOutputStream(f));
  }
  if (filename.endsWith(".bin")) {
    suffixAppropriateWriter=new BinaryGISModelWriter(model,new DataOutputStream(output));
  }
 else {
    suffixAppropriateWriter=new PlainTextGISModelWriter(model,new BufferedWriter(new OutputStreamWriter(output)));
  }
}
 

Example 87

From project org.eclipse.scout.builder, under directory /org.eclipse.scout.releng.ant/src/org/eclipse/scout/releng/ant/pack200/.

Source file: Pack.java

  30 
vote

private void packFile(File inputFile,String outputFilename) throws IOException {
  log("pack200: pack file '" + inputFile.getName() + "'",Project.MSG_INFO);
  Packer packer=Pack200Utility.createPacker();
  OutputStream out=null;
  try {
    if (isGzip()) {
      outputFilename+=".gz";
    }
    File outputFile=new File(outputFilename);
    if (!outputFile.exists()) {
      outputFile.getParentFile().mkdirs();
    }
    out=new FileOutputStream(outputFile);
    if (isGzip()) {
      out=new GZIPOutputStream(out);
    }
    packer.pack(new JarFile(inputFile),out);
  }
  finally {
    if (out != null) {
      out.close();
    }
  }
}
 

Example 88

From project rolefen, under directory /dependency/apache-tomcat-6.0.26/webapps/examples/WEB-INF/classes/compressionFilters/.

Source file: CompressionResponseStream.java

  30 
vote

public void writeToGZip(byte b[],int off,int len) throws IOException {
  if (debug > 1) {
    System.out.println("writeToGZip, len = " + len);
  }
  if (debug > 2) {
    System.out.print("writeToGZip(");
    System.out.write(b,off,len);
    System.out.println(")");
  }
  if (gzipstream == null) {
    if (debug > 1) {
      System.out.println("new GZIPOutputStream");
    }
    if (response.isCommitted()) {
      if (debug > 1)       System.out.print("Response already committed. Using original output stream");
      gzipstream=output;
    }
 else {
      response.addHeader("Content-Encoding","gzip");
      gzipstream=new GZIPOutputStream(output);
    }
  }
  gzipstream.write(b,off,len);
}
 

Example 89

From project rollyourowncbf, under directory /apache-tomcat-6.0.32/webapps/examples/WEB-INF/classes/compressionFilters/.

Source file: CompressionResponseStream.java

  30 
vote

public void writeToGZip(byte b[],int off,int len) throws IOException {
  if (debug > 1) {
    System.out.println("writeToGZip, len = " + len);
  }
  if (debug > 2) {
    System.out.print("writeToGZip(");
    System.out.write(b,off,len);
    System.out.println(")");
  }
  if (gzipstream == null) {
    if (debug > 1) {
      System.out.println("new GZIPOutputStream");
    }
    if (response.isCommitted()) {
      if (debug > 1)       System.out.print("Response already committed. Using original output stream");
      gzipstream=output;
    }
 else {
      response.addHeader("Content-Encoding","gzip");
      gzipstream=new GZIPOutputStream(output);
    }
  }
  gzipstream.write(b,off,len);
}
 

Example 90

From project sleeparchiver, under directory /src/com/pavelfatin/sleeparchiver/model/.

Source file: Document.java

  30 
vote

public void saveAs(File file,boolean backup) throws IOException {
  byte[] bytes=saveToBytes();
  if (backup && file.exists()) {
    createBackup(file);
  }
  OutputStream out=new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
  try {
    out.write(bytes);
    out.flush();
    setLocation(file);
  }
  finally {
    Utilities.close(out);
  }
}
 

Example 91

From project tiled-java, under directory /src/tiled/io/xml/.

Source file: XMLMapWriter.java

  30 
vote

/** 
 * Saves a map to an XML file.
 * @param filename the filename of the map file
 */
public void writeMap(Map map,String filename) throws Exception {
  OutputStream os=new FileOutputStream(filename);
  if (filename.endsWith(".tmx.gz")) {
    os=new GZIPOutputStream(os);
  }
  Writer writer=new OutputStreamWriter(os,Charset.forName("UTF-8"));
  XMLWriter xmlWriter=new XMLWriter(writer);
  xmlWriter.startDocument();
  writeMap(map,xmlWriter,filename);
  xmlWriter.endDocument();
  writer.flush();
  if (os instanceof GZIPOutputStream) {
    ((GZIPOutputStream)os).finish();
  }
  os.close();
}
 

Example 92

From project tycho.extras, under directory /pack200/tycho-pack200-impl/src/main/java/org/eclipse/tycho/extras/pack200/.

Source file: Pack200Wrapper.java

  30 
vote

private void pack(File jar,File pack) throws IOException, FileNotFoundException {
  JarFile is=new JarFile(jar);
  try {
    OutputStream os=new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(pack)));
    try {
      Packer packer=newPacker();
      packer.pack(is,os);
    }
  finally {
      close(os);
    }
  }
  finally {
    try {
      is.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 93

From project waffle, under directory /Source/ThirdParty/tomcat/webapps/examples/WEB-INF/classes/compressionFilters/.

Source file: CompressionResponseStream.java

  30 
vote

public void writeToGZip(byte b[],int off,int len) throws IOException {
  if (debug > 1) {
    System.out.println("writeToGZip, len = " + len);
  }
  if (debug > 2) {
    System.out.print("writeToGZip(");
    System.out.write(b,off,len);
    System.out.println(")");
  }
  if (gzipstream == null) {
    if (debug > 1) {
      System.out.println("new GZIPOutputStream");
    }
    if (response.isCommitted()) {
      if (debug > 1)       System.out.print("Response already committed. Using original output stream");
      gzipstream=output;
    }
 else {
      response.addHeader("Content-Encoding","gzip");
      gzipstream=new GZIPOutputStream(output);
    }
  }
  gzipstream.write(b,off,len);
}
 

Example 94

From project Android, under directory /app/src/main/java/com/github/mobile/.

Source file: RequestWriter.java

  29 
vote

/** 
 * Write request to file
 * @param request
 * @return request
 */
public <V>V write(V request){
  RandomAccessFile dir=null;
  FileLock lock=null;
  ObjectOutputStream output=null;
  try {
    createDirectory(handle.getParentFile());
    dir=new RandomAccessFile(handle,"rw");
    lock=dir.getChannel().lock();
    output=new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(dir.getFD()),8192));
    output.writeInt(version);
    output.writeObject(request);
  }
 catch (  IOException e) {
    Log.d(TAG,"Exception writing cache " + handle.getName(),e);
    return null;
  }
 finally {
    if (output != null)     try {
      output.close();
    }
 catch (    IOException e) {
      Log.d(TAG,"Exception closing stream",e);
    }
    if (lock != null)     try {
      lock.release();
    }
 catch (    IOException e) {
      Log.d(TAG,"Exception unlocking file",e);
    }
    if (dir != null)     try {
      dir.close();
    }
 catch (    IOException e) {
      Log.d(TAG,"Exception closing file",e);
    }
  }
  return request;
}
 

Example 95

From project cascading, under directory /src/hadoop/cascading/flow/hadoop/util/.

Source file: JavaObjectSerializer.java

  29 
vote

@Override public <T>byte[] serialize(T object,boolean compress) throws IOException {
  if (object instanceof Map)   return serializeMap((Map<String,?>)object,compress);
  if (object instanceof List)   return serializeList((List<?>)object,compress);
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  ObjectOutputStream out=new ObjectOutputStream(compress ? new GZIPOutputStream(bytes) : bytes);
  try {
    out.writeObject(object);
  }
  finally {
    out.close();
  }
  return bytes.toByteArray();
}
 

Example 96

From project HarleyDroid, under directory /src/org/harleydroid/.

Source file: HarleyDroidLogger.java

  29 
vote

public void start(){
  if (D)   Log.d(TAG,"start()");
  if (mGPS != null)   mGPS.start();
  try {
    File path=new File(Environment.getExternalStorageDirectory(),"/Android/data/org.harleydroid/files/");
    path.mkdirs();
    File logFile=new File(path,"harley-" + TIMESTAMP_FORMAT.format(new Date()) + ".log.gz");
    mLog=new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(logFile,false)));
  }
 catch (  IOException e) {
    Log.d(TAG,"Logfile open " + e);
  }
}
 

Example 97

From project jCAE, under directory /amibe/src/org/jcae/mesh/xmldata/.

Source file: MeshExporter.java

  29 
vote

/** 
 * @param fileName The UNV filename. If the name ends with ".gz" it willbe zlib compressed.
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public final void write(String fileName){
  logger.info("Export into file " + fileName + " (format "+ getClass().getSimpleName()+ ")");
  try {
    FileOutputStream fos=new FileOutputStream(fileName);
    BufferedOutputStream bos=new BufferedOutputStream(fos);
    PrintStream pstream;
    if (fileName.endsWith(".gz"))     pstream=new PrintStream(new GZIPOutputStream(bos));
 else     pstream=new PrintStream(bos);
    write(pstream);
    pstream.close();
  }
 catch (  IOException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
catch (  ParserConfigurationException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
catch (  SAXException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}
 

Example 98

From project jena-tdb, under directory /src/main/java/org/apache/jena/tdb/store/bulkloader3/.

Source file: DataStreamFactory.java

  29 
vote

public static DataOutputStream createDataOutputStream(OutputStream out,boolean buffered,boolean gzip_outside,boolean compression,int buffer_size){
  try {
    if (!buffered) {
      return new DataOutputStream(compression ? new GZIPOutputStream(out) : out);
    }
 else {
      if (gzip_outside) {
        return new DataOutputStream(compression ? new GZIPOutputStream(new BufferedOutputStream(out,buffer_size)) : new BufferedOutputStream(out,buffer_size));
      }
 else {
        return new DataOutputStream(compression ? new BufferedOutputStream(new GZIPOutputStream(out,buffer_size)) : new BufferedOutputStream(out,buffer_size));
      }
    }
  }
 catch (  IOException e) {
    throw new AtlasException(e);
  }
}
 

Example 99

From project kabeja, under directory /core/src/main/java/org/kabeja/xml/.

Source file: SAXPrettyOutputter.java

  29 
vote

public void setOutput(OutputStream out){
  OutputStream bout=null;
  try {
    if (gzip) {
      bout=new BufferedOutputStream(new GZIPOutputStream(out));
    }
 else {
      bout=new BufferedOutputStream(out);
    }
    this.out=new OutputStreamWriter(bout,this.encoding);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 100

From project MineStarLibrary, under directory /src/main/java/de/minestar/minestarlibrary/data/tools/.

Source file: CompressedStreamTools.java

  29 
vote

public static void writeGzippedCompoundToOutputStream(NBTTagCompound nbttag,OutputStream output) throws IOException {
  DataOutputStream dataoutputstream=new DataOutputStream(new GZIPOutputStream(output));
  try {
    writeTo(nbttag,dataoutputstream);
  }
  finally {
    dataoutputstream.close();
  }
}
 

Example 101

From project mkgmap, under directory /src/uk/me/parabola/mkgmap/sea/optional/.

Source file: PrecompSeaSaver.java

  29 
vote

private void writeIndex(){
  try {
    PrintWriter indexWriter=new PrintWriter(new GZIPOutputStream(new FileOutputStream(new File(outputDir,"index.txt.gz"))));
    for (    Entry<String,String> ind : index.entrySet()) {
      indexWriter.format("%s;%s\n",ind.getKey(),ind.getValue());
    }
    indexWriter.close();
  }
 catch (  IOException exp1) {
    exp1.printStackTrace();
  }
}
 

Example 102

From project p2-browser, under directory /com.ifedorenko.p2browser/src/com/ifedorenko/p2browser/director/.

Source file: InstallableUnitDAG.java

  29 
vote

public void print(File file){
  try {
    PrintStream out=new PrintStream(new GZIPOutputStream(new FileOutputStream(file)));
    try {
      print(out);
    }
  finally {
      out.close();
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 103

From project Psh, under directory /org/spiderland/Psh/.

Source file: GA.java

  29 
vote

protected void Checkpoint() throws Exception {
  if (_checkpointPrefix == null)   return;
  File file=new File(_checkpointPrefix + _checkpoint.checkpointNumber + ".gz");
  ObjectOutputStream out=new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
  out.writeObject(_checkpoint);
  out.flush();
  out.close();
  System.out.println("Wrote checkpoint file " + file.getAbsolutePath());
  _checkpoint.checkpointNumber++;
}
 

Example 104

From project qi4j-core, under directory /io/src/main/java/org/qi4j/io/.

Source file: Outputs.java

  29 
vote

/** 
 * Write lines to a text file. Separate each line with a newline ("\n" character). If the writing or sending fails, the file is deleted. <p/> If the filename ends with .gz, then the data is automatically GZipped.
 * @param file the file to save the text to
 * @return an Output for storing text in a file
 */
public static Output<String,IOException> text(final File file,final String encoding){
  return new Output<String,IOException>(){
    @Override public <SenderThrowableType extends Throwable>void receiveFrom(    Sender<? extends String,SenderThrowableType> sender) throws IOException, SenderThrowableType {
      File tmpFile=File.createTempFile(file.getName(),".bin");
      OutputStream stream=new FileOutputStream(tmpFile);
      if (file.getName().endsWith(".gz")) {
        stream=new GZIPOutputStream(stream);
      }
      final BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(stream,encoding));
      try {
        sender.sendTo(new Receiver<String,IOException>(){
          public void receive(          String item) throws IOException {
            writer.append(item).append('\n');
          }
        }
);
        writer.close();
        if (!file.exists() || file.delete())         tmpFile.renameTo(file);
      }
 catch (      IOException e) {
        writer.close();
        tmpFile.delete();
      }
catch (      Throwable senderThrowableType) {
        writer.close();
        tmpFile.delete();
        throw (SenderThrowableType)senderThrowableType;
      }
    }
  }
;
}
 

Example 105

From project sparqled, under directory /sparql-summary/src/main/java/org/sindice/summary/.

Source file: Dump.java

  29 
vote

/** 
 * Open a file in order to create a RDF ouput.
 * @param outputFile The file output.
 * @param domain The domain of the query.
 */
public void openRDF(String outputFile,String domain){
  Logger logger=Logger.getLogger("org.sindice.summary.dump");
  try {
    _output=new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile))));
    _domain=domain;
    if (domain.equals("sindice.com")) {
      _sndDomain=domain;
    }
 else {
      _sndDomain=URIUtil.getSndDomainFromUrl(domain);
    }
    _nodeCounter=0;
  }
 catch (  Exception e) {
    logger.debug("Error: " + e.getMessage());
  }
}
 

Example 106

From project texnlp, under directory /src/main/java/texnlp/estimate/.

Source file: TadmClassifier.java

  29 
vote

private void saveEvents(){
  try {
    BufferedWriter eventsWriter=new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(eventsFile))));
    int testCounter=0;
    THashSet<String> seenOnce=new THashSet<String>();
    THashSet<String> seenTwice=new THashSet<String>();
    for (    Context c : events.keySet()) {
      for (int m=0; m < c.contexts.length; m++)       if (!seenOnce.add(c.contexts[m]))       seenTwice.add(c.contexts[m]);
    }
    seenOnce=null;
    for (    Context c : events.keySet()) {
      FeatureCounts fcounts=new FeatureCounts(fmap,numLabels);
      for (int m=0; m < c.contexts.length; m++)       if (seenTwice.contains(c.contexts[m]))       fcounts.observeFeature(c.contexts[m]);
      eventsWriter.write(fcounts.toString(events.get(c)));
      if ((testCounter++ % 1000) == 0)       System.out.print(";");
    }
    System.out.println();
    System.out.println(name + " -- " + fmap.getNumFeatures());
    eventsWriter.flush();
    eventsWriter.close();
    events=null;
    fmap.cap();
  }
 catch (  IOException e) {
    System.out.println("Unable to save events to " + eventsFile);
    System.out.println(e);
  }
}
 

Example 107

From project textgrounder, under directory /old/src/main/java/opennlp/textgrounder/bayesian/converters/.

Source file: ProbabilityPrettyPrinterRLDA.java

  29 
vote

/** 
 */
@Override public void normalizeAndPrintWordByRegion(){
  try {
    String wordByRegionFilename=experimentParameters.getWordByRegionProbabilitiesPath();
    BufferedWriter wordByRegionWriter=new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(wordByRegionFilename))));
    double sum=0.;
    for (int i=0; i < L; ++i) {
      sum+=averagedRegionCounts[i];
    }
    for (int i=0; i < L; ++i) {
      ArrayList<IntDoublePair> topWords=new ArrayList<IntDoublePair>();
      for (int j=0; j < W; ++j) {
        topWords.add(new IntDoublePair(j,averagedWordByRegionCounts[j * L + i]));
      }
      Collections.sort(topWords);
      Region region=regionIdToRegionMap.get(i);
      wordByRegionWriter.write(String.format("Region%04d\t%.2f\t%.2f\t%.8e",i,region.centLon,region.centLat,averagedRegionCounts[i] / sum));
      wordByRegionWriter.newLine();
      for (      IntDoublePair pair : topWords) {
        wordByRegionWriter.write(String.format("%s\t%.8e",lexicon.getWordForInt(pair.index),pair.count / averagedRegionCounts[i]));
        wordByRegionWriter.newLine();
      }
      wordByRegionWriter.newLine();
    }
    wordByRegionWriter.close();
  }
 catch (  FileNotFoundException ex) {
    Logger.getLogger(ProbabilityPrettyPrinterRLDA.class.getName()).log(Level.SEVERE,null,ex);
    System.exit(1);
  }
catch (  IOException ex) {
    Logger.getLogger(ProbabilityPrettyPrinterRLDA.class.getName()).log(Level.SEVERE,null,ex);
    System.exit(1);
  }
}
 

Example 108

From project webutilities, under directory /src/main/java/com/googlecode/webutilities/filters/compression/.

Source file: EncodedStreamsFactory.java

  29 
vote

public CompressedOutput getCompressedStream(final OutputStream outputStream) throws IOException {
  return new CompressedOutput(){
    private final GZIPOutputStream gzipOutputStream=new GZIPOutputStream(outputStream);
    public OutputStream getCompressedOutputStream(){
      return gzipOutputStream;
    }
    public void finish() throws IOException {
      gzipOutputStream.finish();
    }
  }
;
}
 

Example 109

From project XenMaster, under directory /src/main/java/org/xenmaster/web/.

Source file: SetupHook.java

  29 
vote

@Override public void handle(RequestBundle rb) throws IOException {
  Logger.getLogger(getClass()).info("Preseed request " + rb.getRequestURI());
  FileInputStream fis=null;
  String store=Settings.getInstance().getString("StorePath");
switch (rb.getPathParts()[0]) {
case "xapi":
    fis=new FileInputStream(store + "/setup/preseed-template.txt");
  break;
case "post-install.sh":
fis=new FileInputStream(store + "/setup/post-install.sh");
break;
case "motd":
fis=new FileInputStream(store + "/setup/motd");
Logger.getLogger(getClass()).info(rb.getRequest().getParameter("IP") + " completed network install");
break;
case "plugins.tar.gz":
try (TarArchiveOutputStream tos=new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(rb.getResponseBody())))){
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
writePluginsToTarball(tos);
tos.close();
return;
}
 catch (IOException ex) {
Logger.getLogger(getClass()).error("Failed to compress plugins",ex);
}
break;
default :
rb.getBaseRequest().setHandled(false);
return;
}
if (fis != null) {
rb.replyWithString(parseTemplate(fis,rb.getRequest().getRemoteAddr()));
}
}