Java Code Examples for java.util.zip.GZIPInputStream

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 eucalyptus, under directory /clc/modules/storage-manager/src/edu/ucsb/eucalyptus/cloud/ws/.

Source file: Bukkit.java

  34 
vote

private void unzipImage(String decryptedImageName,String tarredImageName) throws Exception {
  GZIPInputStream in=new GZIPInputStream(new FileInputStream(new File(decryptedImageName)));
  File outFile=new File(tarredImageName);
  ReadableByteChannel inChannel=Channels.newChannel(in);
  WritableByteChannel outChannel=new FileOutputStream(outFile).getChannel();
  ByteBuffer buffer=ByteBuffer.allocate(WalrusQueryDispatcher.DATA_MESSAGE_SIZE);
  while (inChannel.read(buffer) != -1) {
    buffer.flip();
    outChannel.write(buffer);
    buffer.clear();
  }
  outChannel.close();
  inChannel.close();
}
 

Example 2

From project androidquery, under directory /src/com/androidquery/callback/.

Source file: AbstractAjaxCallback.java

  33 
vote

private void copy(InputStream is,OutputStream os,String encoding,int max) throws IOException {
  if ("gzip".equalsIgnoreCase(encoding)) {
    is=new GZIPInputStream(is);
  }
  Object o=null;
  if (progress != null) {
    o=progress.get();
  }
  Progress p=null;
  if (o != null) {
    p=new Progress(o);
  }
  AQUtility.copy(is,os,max,p);
}
 

Example 3

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

Source file: GunzipDecorator.java

  33 
vote

@Override public void append(Event e) throws IOException {
  byte[] bs=e.get(GZDOC);
  if (bs == null) {
    super.append(e);
    return;
  }
  ByteArrayInputStream bais=new ByteArrayInputStream(bs);
  GZIPInputStream gzis=new GZIPInputStream(bais);
  DataInputStream dis=new DataInputStream(gzis);
  WriteableEvent out=new WriteableEvent();
  out.readFields(dis);
  dis.close();
  super.append(out);
}
 

Example 4

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

Source file: Tools.java

  33 
vote

/** 
 * Decompress GZIP (RFC 1952) compressed data
 * @return A string containing the decompressed data
 */
public static String decompressGzip(byte[] compressedData) throws IOException {
  byte[] buffer=new byte[compressedData.length];
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  GZIPInputStream in=new GZIPInputStream(new ByteArrayInputStream(compressedData));
  for (int bytesRead=0; bytesRead != -1; bytesRead=in.read(buffer)) {
    out.write(buffer,0,bytesRead);
  }
  return new String(out.toByteArray(),"UTF-8");
}
 

Example 5

From project C-Cat, under directory /core/src/main/java/gov/llnl/ontology/text/hbase/.

Source file: GzipTarInputFormat.java

  32 
vote

/** 
 * Extract the  {@link Path} for the file to be processed by this {@link GzipTarRecordReader}.
 */
public void initialize(InputSplit split,TaskAttemptContext context) throws IOException, InterruptedException {
  Configuration config=context.getConfiguration();
  FileSystem fs=FileSystem.get(config);
  FileSplit fileSplit=(FileSplit)split;
  Path filePath=fileSplit.getPath();
  parentName=filePath.getParent().getName();
  InputStream is=fs.open(filePath);
  System.err.println(filePath.toString());
  GZIPInputStream gis=new GZIPInputStream(is);
  tarStream=new TarInputStream(gis);
}
 

Example 6

From project crest, under directory /core/src/test/java/org/codegist/crest/io/http/.

Source file: HttpChannelResponseHttpResourceTest.java

  32 
vote

@Test public void getEntityShouldReturnZippedWrappedIfContentEncodingIsGZIP() throws Exception {
  InputStream stream=mock(InputStream.class);
  GZIPInputStream expected=mock(GZIPInputStream.class);
  when(mockResponse.getContentEncoding()).thenReturn("gzip");
  when(mockResponse.getEntity()).thenReturn(stream);
  whenNew(GZIPInputStream.class).withArguments(stream).thenReturn(expected);
  HttpChannelResponseHttpResource toTest=newToTest();
  assertSame(expected,toTest.getEntity());
  assertEquals("gzip",toTest.getContentEncoding());
}
 

Example 7

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

Source file: GzipCompressionProvider.java

  32 
vote

@Override public byte[] decompress(String path,byte[] compressedData) throws Exception {
  ByteArrayOutputStream bytes=new ByteArrayOutputStream(compressedData.length);
  GZIPInputStream in=new GZIPInputStream(new ByteArrayInputStream(compressedData));
  byte[] buffer=new byte[compressedData.length];
  for (; ; ) {
    int bytesRead=in.read(buffer,0,buffer.length);
    if (bytesRead < 0) {
      break;
    }
    bytes.write(buffer,0,bytesRead);
  }
  return bytes.toByteArray();
}
 

Example 8

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

Source file: GZIPChannel.java

  32 
vote

protected void getMessage(byte[] b,int offset,int len) throws IOException, ISOException {
  int total=0;
  GZIPInputStream gzip=new GZIPInputStream(serverIn);
  while (total < len) {
    int nread=gzip.read(b,offset,len - total);
    if (nread == -1) {
      throw new ISOException("End of compressed stream reached before all data was read");
    }
    total+=nread;
    offset+=nread;
  }
}
 

Example 9

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

Source file: GZIPUtils.java

  32 
vote

/** 
 * Returns an gunzipped copy of the input array.  
 * @throws IOException if the input cannot be properly decompressed
 */
public static final byte[] unzip(byte[] in) throws IOException {
  ByteArrayOutputStream outStream=new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
  GZIPInputStream inStream=new GZIPInputStream(new ByteArrayInputStream(in));
  byte[] buf=new byte[BUF_SIZE];
  while (true) {
    int size=inStream.read(buf);
    if (size <= 0)     break;
    outStream.write(buf,0,size);
  }
  outStream.close();
  return outStream.toByteArray();
}
 

Example 10

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

Source file: ImportExportCommand.java

  32 
vote

private static LilithPreferences readPersistence(File file) throws IOException {
  GZIPInputStream is=null;
  try {
    is=new GZIPInputStream(new BufferedInputStream(new FileInputStream(file)));
    LilithPreferencesStreamingDecoder decoder=new LilithPreferencesStreamingDecoder();
    return decoder.decode(is);
  }
  finally {
    if (is != null) {
      is.close();
    }
  }
}
 

Example 11

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

Source file: GZIPUtils.java

  32 
vote

/** 
 * Returns an gunzipped copy of the input array.  
 * @throws IOException if the input cannot be properly decompressed
 */
public static final byte[] unzip(byte[] in) throws IOException {
  ByteArrayOutputStream outStream=new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
  GZIPInputStream inStream=new GZIPInputStream(new ByteArrayInputStream(in));
  byte[] buf=new byte[BUF_SIZE];
  while (true) {
    int size=inStream.read(buf);
    if (size <= 0)     break;
    outStream.write(buf,0,size);
  }
  outStream.close();
  return outStream.toByteArray();
}
 

Example 12

From project onebusaway-nyc, under directory /onebusaway-nyc-util/src/main/java/org/onebusaway/nyc/util/impl/.

Source file: FileUtility.java

  32 
vote

/** 
 * Ungzip an input file into an output file. <p> The output file is created in the output folder, having the same name as the input file, minus the '.gz' extension.
 * @param inputFile the input .gz file
 * @param outputDir the output directory file.
 * @throws IOException
 * @throws FileNotFoundException
 * @return The {@File} with the ungzipped content.
 */
public File unGzip(final File inputFile,final File outputDir) throws FileNotFoundException, IOException {
  _log.info(String.format("Ungzipping %s to dir %s.",inputFile.getAbsolutePath(),outputDir.getAbsolutePath()));
  final File outputFile=new File(outputDir,inputFile.getName().substring(0,inputFile.getName().length() - 3));
  final GZIPInputStream in=new GZIPInputStream(new FileInputStream(inputFile));
  final FileOutputStream out=new FileOutputStream(outputFile);
  IOUtils.copy(in,out);
  in.close();
  out.close();
  return outputFile;
}
 

Example 13

From project agorava-core, under directory /agorava-core-impl/src/main/java/org/agorava/core/oauth/scribe/.

Source file: RestResponseScribe.java

  31 
vote

/** 
 * {@inheritDoc}This implementation support also gzip encoding in the response
 * @return
 */
@Override public InputStream getStream(){
  InputStream res;
  if (GZIP_CONTENT_ENCODING.equals(getHeaders().get(CONTENT_ENCODING)))   try {
    res=new GZIPInputStream(getDelegate().getStream());
  }
 catch (  IOException e) {
    throw new AgoravaException("Unable to create GZIPInputStream",e);
  }
 else   res=getDelegate().getStream();
  return res;
}
 

Example 14

From project agraph-java-client, under directory /src/com/franz/agraph/http/handler/.

Source file: AGResponseHandler.java

  31 
vote

protected static InputStream getInputStream(HttpMethod method) throws IOException {
  InputStream is=method.getResponseBodyAsStream();
  Header h=method.getResponseHeader("Content-Encoding");
  if (h != null && h.getValue().equals("gzip")) {
    is=new GZIPInputStream(is);
  }
  return is;
}
 

Example 15

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: OcrInitAsyncTask.java

  31 
vote

/** 
 * Unzips the given Gzipped file to the given destination, and deletes the gzipped file.
 * @param zippedFile The gzipped file to be uncompressed
 * @param outFilePath File to unzip to, including path
 * @throws FileNotFoundException
 * @throws IOException
 */
private void gunzip(File zippedFile,File outFilePath) throws FileNotFoundException, IOException {
  int uncompressedFileSize=getGzipSizeUncompressed(zippedFile);
  Integer percentComplete;
  int percentCompleteLast=0;
  int unzippedBytes=0;
  final Integer progressMin=0;
  int progressMax=100 - progressMin;
  publishProgress("Uncompressing data for " + languageName + "...",progressMin.toString());
  String extension=zippedFile.toString().substring(zippedFile.toString().length() - 16);
  if (extension.equals(".tar.gz.download")) {
    progressMax=50;
  }
  GZIPInputStream gzipInputStream=new GZIPInputStream(new BufferedInputStream(new FileInputStream(zippedFile)));
  OutputStream outputStream=new FileOutputStream(outFilePath);
  BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(outputStream);
  final int BUFFER=8192;
  byte[] data=new byte[BUFFER];
  int len;
  while ((len=gzipInputStream.read(data,0,BUFFER)) > 0) {
    bufferedOutputStream.write(data,0,len);
    unzippedBytes+=len;
    percentComplete=(int)((unzippedBytes / (float)uncompressedFileSize) * progressMax) + progressMin;
    if (percentComplete > percentCompleteLast) {
      publishProgress("Uncompressing data for " + languageName + "...",percentComplete.toString());
      percentCompleteLast=percentComplete;
    }
  }
  gzipInputStream.close();
  bufferedOutputStream.flush();
  bufferedOutputStream.close();
  if (zippedFile.exists()) {
    zippedFile.delete();
  }
}
 

Example 16

From project android-tether, under directory /src/og/android/tether/system/.

Source file: Configuration.java

  31 
vote

public static boolean hasKernelFeature(String feature){
  try {
    File cfg=new File("/proc/config.gz");
    if (cfg.exists() == false) {
      return true;
    }
    FileInputStream fis=new FileInputStream(cfg);
    GZIPInputStream gzin=new GZIPInputStream(fis);
    BufferedReader in=null;
    String line="";
    in=new BufferedReader(new InputStreamReader(gzin));
    while ((line=in.readLine()) != null) {
      if (line.startsWith(feature)) {
        gzin.close();
        return true;
      }
    }
    gzin.close();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return false;
}
 

Example 17

From project anode, under directory /app/src/org/meshpoint/anode/util/.

Source file: TarExtractor.java

  31 
vote

public void unpack(File src,File dest) throws IOException {
  File tarFile=new File(src.getAbsolutePath() + ".tar");
  byte[] buf=new byte[1024];
  GZIPInputStream zis=null;
  zis=new GZIPInputStream(new FileInputStream(src));
  FileOutputStream tarfos=new FileOutputStream(tarFile);
  int count;
  while ((count=zis.read(buf,0,1024)) != -1)   tarfos.write(buf,0,count);
  tarfos.close();
  zis.close();
  TarInputStream tis=new TarInputStream(new BufferedInputStream(new FileInputStream(tarFile)));
  TarEntry entry;
  while ((entry=tis.getNextEntry()) != null) {
    File entryFile=new File(dest,entry.getName());
    File parentDir=new File(entryFile.getParent());
    if (!parentDir.isDirectory() && !parentDir.mkdirs())     throw new IOException("TarExtractor.unpack(): unable to create directory");
    FileOutputStream fos=new FileOutputStream(entryFile);
    BufferedOutputStream bos=new BufferedOutputStream(fos);
    while ((count=tis.read(buf)) != -1)     bos.write(buf,0,count);
    bos.flush();
    bos.close();
  }
  tis.close();
  tarFile.delete();
}
 

Example 18

From project apps-for-android, under directory /Translate/src/com/beust/android/translate/.

Source file: TranslateActivity.java

  31 
vote

/** 
 * Pick a random word and set it as the input word.
 */
public void selectRandomWord(){
  BufferedReader fr=null;
  try {
    GZIPInputStream is=new GZIPInputStream(getResources().openRawResource(R.raw.dictionary));
    if (mWordBuffer == null) {
      mWordBuffer=new byte[601000];
      int n=is.read(mWordBuffer,0,mWordBuffer.length);
      int current=n;
      while (n != -1) {
        n=is.read(mWordBuffer,current,mWordBuffer.length - current);
        current+=n;
      }
      is.close();
      mWordCount=0;
      mWordIndices=Lists.newArrayList();
      for (int i=0; i < mWordBuffer.length; i++) {
        if (mWordBuffer[i] == '\n') {
          mWordCount++;
          mWordIndices.add(i);
        }
      }
      log("Found " + mWordCount + " words");
    }
    int randomWordIndex=(int)(System.currentTimeMillis() % (mWordCount - 1));
    log("Random word index:" + randomWordIndex + " wordCount:"+ mWordCount);
    int start=mWordIndices.get(randomWordIndex);
    int end=mWordIndices.get(randomWordIndex + 1);
    byte[] b=new byte[end - start - 2];
    System.arraycopy(mWordBuffer,start + 1,b,0,(end - start - 2));
    String randomWord=new String(b);
    mFromEditText.setText(randomWord);
    updateButton(mFromButton,Language.findLanguageByShortName(Language.ENGLISH.getShortName()),true);
  }
 catch (  FileNotFoundException e) {
    Log.e(TAG,e.getMessage(),e);
  }
catch (  IOException e) {
    Log.e(TAG,e.getMessage(),e);
  }
}
 

Example 19

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

Source file: ZipUtils.java

  31 
vote

public static byte[] gunzip(byte[] input) throws IOException {
  byte b[]=buf.get();
  ByteArrayOutputStream o=out.get();
  o.reset();
  GZIPInputStream z=null;
  try {
    z=new GZIPInputStream(new ByteArrayInputStream(input));
    int read=0;
    while ((read=z.read(b)) > 0) {
      o.write(b,0,read);
    }
    o.flush();
  }
  finally {
    if (z != null) {
      z.close();
    }
  }
  return o.toByteArray();
}
 

Example 20

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

Source file: XMLParser.java

  31 
vote

@Override public Network parse(Network net,File f) throws ENException {
  try {
    InputStream is=!gzipped ? new FileInputStream(f) : new GZIPInputStream(new FileInputStream(f));
    InputStreamReader r=new InputStreamReader(is,"UTF-8");
    return (Network)X_STREAM.fromXML(r);
  }
 catch (  IOException e) {
    throw new ENException(302);
  }
}
 

Example 21

From project ceres, under directory /ceres-core/src/main/java/com/bc/ceres/core/.

Source file: VirtualDir.java

  31 
vote

@Override public InputStream getInputStream(String path) throws IOException {
  if (path.endsWith(".gz")) {
    return new GZIPInputStream(new FileInputStream(getFile(path)));
  }
  return new FileInputStream(getFile(path));
}
 

Example 22

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

Source file: FileUtils.java

  31 
vote

/** 
 * This function determines if a byte array is gzip compressed and uncompress it
 * @param source properly gzip compressed byte array
 * @return uncompressed byte array
 * @throws IOException
 */
public static byte[] uncompressGZipArray(byte[] source) throws IOException {
  if (source == null)   return null;
  if ((source.length > 1) && (((source[1] << 8) | (source[0] & 0xff)) == GZIPInputStream.GZIP_MAGIC)) {
    System.out.println("DEBUG: uncompressGZipArray - uncompressing source");
    try {
      final ByteArrayInputStream byteInput=new ByteArrayInputStream(source);
      final ByteArrayOutputStream byteOutput=new ByteArrayOutputStream(source.length / 5);
      final GZIPInputStream zippedContent=new GZIPInputStream(byteInput);
      final byte[] data=new byte[1024];
      int read=0;
      while ((read=zippedContent.read(data,0,1024)) != -1) {
        byteOutput.write(data,0,read);
      }
      zippedContent.close();
      byteOutput.close();
      source=byteOutput.toByteArray();
    }
 catch (    final Exception e) {
      if (!e.getMessage().equals("Not in GZIP format")) {
        throw new IOException(e.getMessage());
      }
    }
  }
  return source;
}
 

Example 23

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

Source file: CompressionUtil.java

  31 
vote

@Override public void uncompress(InputStream srcIn,OutputStream destOut) throws IOException {
  GZIPInputStream in=null;
  try {
    in=new GZIPInputStream(srcIn);
    byte[] buf=new byte[1024];
    int len;
    while ((len=in.read(buf)) > 0) {
      destOut.write(buf,0,len);
    }
    in.close();
    in=null;
    destOut.close();
    destOut=null;
  }
  finally {
    if (in != null) {
      try {
        in.close();
      }
 catch (      Exception e) {
      }
    }
    if (destOut != null) {
      try {
        destOut.close();
      }
 catch (      Exception e) {
      }
    }
  }
}
 

Example 24

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

Source file: GZIPSerializer.java

  31 
vote

/** 
 * {@inheritDoc}
 */
@Override public <T>T deserialize(InputStream in,Class<T> type,int bufferSize) throws IOException {
  in=new GZIPInputStream(in,bufferSize);
  try {
    return _serializer.deserialize(in,type,bufferSize);
  }
  finally {
    if (isCloseEnabled()) {
      in.close();
    }
  }
}
 

Example 25

From project crammer, under directory /src/main/java/net/sf/samtools/.

Source file: SAMFileReader.java

  31 
vote

/** 
 * Attempts to check whether the file is a gzipped sam file. Returns true if it is and false otherwise.
 */
private boolean isGzippedSAMFile(final BufferedInputStream stream){
  if (!stream.markSupported()) {
    throw new IllegalArgumentException("Cannot test a stream that doesn't support marking.");
  }
  stream.mark(8000);
  try {
    final GZIPInputStream gunzip=new GZIPInputStream(stream);
    final int ch=gunzip.read();
    return true;
  }
 catch (  IOException ioe) {
    return false;
  }
 finally {
    try {
      stream.reset();
    }
 catch (    IOException ioe) {
      throw new IllegalStateException("Could not reset stream.");
    }
  }
}
 

Example 26

From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/proxy/.

Source file: HttpResponseHandler.java

  31 
vote

public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
  Header contentEncodingHeader=response.getFirstHeader("Content-Encoding");
  StringBuffer responseBuffer=new StringBuffer();
  if (contentEncodingHeader != null) {
    byte[] buf=new byte[512];
    int len;
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    if ("gzip".equalsIgnoreCase(contentEncodingHeader.getValue())) {
      GZIPInputStream gzipInputStream=new GZIPInputStream(response.getEntity().getContent());
      while ((len=gzipInputStream.read(buf,0,512)) != -1) {
        bos.write(buf,0,len);
      }
      responseBuffer.append(new String(bos.toByteArray()));
    }
 else     if ("zip".equalsIgnoreCase(contentEncodingHeader.getValue())) {
      ZipInputStream zipInputStream=new ZipInputStream(response.getEntity().getContent());
      while ((len=zipInputStream.read(buf,0,512)) != -1) {
        bos.write(buf,0,len);
      }
      responseBuffer.append(new String(bos.toByteArray()));
    }
 else {
      logger.error("Unable to deflate this Content-Encoding : " + contentEncodingHeader.getValue());
      throw new IOException("Unable to deflate this Content-Encoding : " + contentEncodingHeader.getValue());
    }
  }
 else {
    InputStreamReader in=new InputStreamReader(response.getEntity().getContent());
    BufferedReader bin=new BufferedReader(in);
    String line;
    do {
      line=bin.readLine();
      if (line != null) {
        responseBuffer.append(line);
      }
    }
 while (line != null);
  }
  return responseBuffer.toString();
}
 

Example 27

From project FlipDroid, under directory /lib/weibo4j/src/weibo4j/http/.

Source file: Response.java

  31 
vote

public Response(HttpURLConnection con) throws IOException {
  this.con=con;
  this.statusCode=con.getResponseCode();
  if (null == (is=con.getErrorStream())) {
    is=con.getInputStream();
  }
  if (null != is && "gzip".equals(con.getContentEncoding())) {
    is=new GZIPInputStream(is);
  }
}
 

Example 28

From project flume, under directory /flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/.

Source file: TestHDFSCompressedDataStream.java

  31 
vote

@Test public void testGzipDurability() throws IOException {
  File file=new File("target/test/data/foo.gz");
  String fileURI=file.getAbsoluteFile().toURI().toString();
  logger.info("File URI: {}",fileURI);
  Configuration conf=new Configuration();
  conf.set("fs.file.impl","org.apache.hadoop.fs.RawLocalFileSystem");
  Path path=new Path(fileURI);
  FileSystem fs=path.getFileSystem(conf);
  CompressionCodecFactory factory=new CompressionCodecFactory(conf);
  HDFSCompressedDataStream writer=new HDFSCompressedDataStream();
  FlumeFormatter fmt=new HDFSTextFormatter();
  writer.open(fileURI,factory.getCodec(new Path(fileURI)),SequenceFile.CompressionType.BLOCK,fmt);
  String body="yarf!";
  Event evt=EventBuilder.withBody(body,Charsets.UTF_8);
  writer.append(evt,fmt);
  writer.sync();
  byte[] buf=new byte[256];
  GZIPInputStream cmpIn=new GZIPInputStream(new FileInputStream(file));
  int len=cmpIn.read(buf);
  String result=new String(buf,0,len,Charsets.UTF_8);
  result=result.trim();
  Assert.assertEquals("input and output must match",body,result);
}
 

Example 29

From project Game_3, under directory /core/tests/playn/core/json/.

Source file: InternalJsonParserTest.java

  31 
vote

@Test public void tortureTest() throws JsonParserException, IOException {
  InputStream input=getClass().getResourceAsStream("torturetest.json.gz");
  JsonObject o=JsonParser.object().from(readAsUtf8(new GZIPInputStream(input)));
  assertNotNull(o.get("a"));
  assertNotNull(o.getObject("a").getArray("b\uecee\u8324\u007a\\\ue768.N"));
  String json=new JsonStringWriter().object(o).write();
  JsonObject o2=JsonParser.object().from(json);
  new JsonStringWriter().object(o2).write();
}
 

Example 30

From project git-starteam, under directory /fake-starteam/src/com/starbase/starteam/.

Source file: File.java

  31 
vote

private void copyFromGz(java.io.File source,java.io.File target) throws IOException {
  GZIPInputStream gzin=null;
  FileInputStream fin=null;
  FileOutputStream fout=null;
  if (!source.exists()) {
    throw new InvalidOperationException("Could not find the storing folder");
  }
  fin=new FileInputStream(source.getCanonicalPath() + java.io.File.separator + FILE_STORED);
  gzin=new GZIPInputStream(fin);
  fout=new FileOutputStream(target);
  byte[] buffer=new byte[1024 * 64];
  int read=gzin.read(buffer);
  while (read >= 0) {
    fout.write(buffer,0,read);
    read=gzin.read(buffer);
  }
  FileUtility.close(fout,gzin,fin);
}
 

Example 31

From project github-api, under directory /src/main/java/org/kohsuke/github/.

Source file: Requester.java

  31 
vote

/** 
 * Handles the "Content-Encoding" header.
 */
private InputStream wrapStream(HttpURLConnection uc,InputStream in) throws IOException {
  String encoding=uc.getContentEncoding();
  if (encoding == null || in == null)   return in;
  if (encoding.equals("gzip"))   return new GZIPInputStream(in);
  throw new UnsupportedOperationException("Unexpected Content-Encoding: " + encoding);
}
 

Example 32

From project gs-core, under directory /src/org/graphstream/stream/file/.

Source file: FileSourceDGS1And2.java

  31 
vote

@Override protected Reader createReaderFrom(String file) throws FileNotFoundException {
  InputStream is=null;
  try {
    is=new GZIPInputStream(new FileInputStream(file));
  }
 catch (  IOException e) {
    is=new FileInputStream(file);
  }
  return new BufferedReader(new InputStreamReader(is));
}
 

Example 33

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

Source file: JavaGzipCompressionCodec.java

  31 
vote

@Override public int decompress(byte[] src,int srcOffset,int srcLength,byte[] dst,int dstOff){
  if (srcLength - srcOffset == 0) {
    return 0;
  }
  try {
    ByteArrayInputStream bytesIn=new ByteArrayInputStream(src,srcOffset,srcLength);
    GZIPInputStream gzip=new GZIPInputStream(bytesIn);
    int curOff=dstOff;
    while (curOff < dst.length - dstOff) {
      int amtRead=gzip.read(dst,curOff,dst.length - curOff);
      if (amtRead == -1) {
        break;
      }
      curOff+=amtRead;
    }
    return curOff;
  }
 catch (  IOException e) {
    throw new RuntimeException("Unexpected IOException while decompressing!",e);
  }
}
 

Example 34

From project Hawksword, under directory /src/com/bw/hawksword/ocr/.

Source file: OcrInitAsyncTask.java

  31 
vote

/** 
 * Unzips the given Gzipped file to the given destination, and deletes the gzipped file.
 * @param zippedFile The gzipped file to be uncompressed
 * @param outFilePath File to unzip to, including path
 * @throws FileNotFoundException
 * @throws IOException
 */
private void gunzip(File zippedFile,File outFilePath) throws FileNotFoundException, IOException {
  int uncompressedFileSize=getGzipSizeUncompressed(zippedFile);
  Integer percentComplete;
  int percentCompleteLast=0;
  int unzippedBytes=0;
  final Integer progressMin=0;
  int progressMax=100 - progressMin;
  publishProgress("Uncompressing data for Dictionary...",progressMin.toString());
  String extension=zippedFile.toString().substring(zippedFile.toString().length() - 16);
  if (extension.equals(".tar.gz.download")) {
    progressMax=50;
  }
  GZIPInputStream gzipInputStream=new GZIPInputStream(new BufferedInputStream(new FileInputStream(zippedFile)));
  OutputStream outputStream=new FileOutputStream(outFilePath);
  BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(outputStream);
  final int BUFFER=8192;
  byte[] data=new byte[BUFFER];
  int len;
  while ((len=gzipInputStream.read(data,0,BUFFER)) > 0) {
    bufferedOutputStream.write(data,0,len);
    unzippedBytes+=len;
    percentComplete=(int)((unzippedBytes / (float)uncompressedFileSize) * progressMax) + progressMin;
    if (percentComplete > percentCompleteLast) {
      publishProgress("Uncompressing data for Dictionary...",percentComplete.toString());
      percentCompleteLast=percentComplete;
    }
  }
  gzipInputStream.close();
  bufferedOutputStream.flush();
  bufferedOutputStream.close();
  if (zippedFile.exists()) {
    zippedFile.delete();
  }
}
 

Example 35

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

Source file: ArchiveUtils.java

  31 
vote

/** 
 * Get a BufferedReader on the crawler journal given TODO: move to a general utils class 
 * @param source File journal
 * @return journal buffered reader.
 * @throws IOException
 */
public static BufferedReader getBufferedReader(File source) throws IOException {
  InputStream is=new BufferedInputStream(new FileInputStream(source));
  boolean isGzipped=source.getName().toLowerCase().endsWith(GZIP_SUFFIX);
  if (isGzipped) {
    is=new GZIPInputStream(is);
  }
  return new BufferedReader(new InputStreamReader(is));
}
 

Example 36

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

Source file: GZip.java

  31 
vote

public String unpack(String a){
  try {
    GZIPInputStream in=new GZIPInputStream(new BufferedInputStream(new FileInputStream(a)));
    String outFilename=a.substring(0,a.lastIndexOf("."));
    OutputStream out=new FileOutputStream(outFilename);
    byte[] buf=new byte[1024];
    int len;
    while ((len=in.read(buf)) > 0) {
      out.write(buf,0,len);
    }
    in.close();
    out.close();
    return outFilename;
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    return null;
  }
}
 

Example 37

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

Source file: IOUtil.java

  31 
vote

public static Object deserialize(InputStream is,boolean compressed){
  GZIPInputStream gis=null;
  ObjectInputStream ois=null;
  try {
    if (compressed) {
      gis=new GZIPInputStream(is);
      is=gis;
    }
    ois=new ObjectInputStream(is);
    Object obj=ois.readObject();
    return obj;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    Execute.close(ois,logger);
    Execute.close(gis,logger);
  }
}
 

Example 38

From project iohack, under directory /src/org/alljoyn/bus/sample/chat/.

Source file: HomeActivity.java

  31 
vote

private void handleLicenseTextCommand(byte[] licenseTextBytes){
  if (gLogPackets) {
    Log.i(ADK.TAG,"License text chunk");
    Log.i(ADK.TAG,Utilities.dumpBytes(licenseTextBytes,licenseTextBytes.length));
  }
  if (licenseTextBytes.length > 1 && licenseTextBytes[0] != 0) {
    mLicenseTextStream.write(licenseTextBytes,1,licenseTextBytes.length - 1);
    sendCommand(CMD_GET_LICENSE,33);
  }
 else {
    try {
      mLicenseTextStream.close();
      byte[] encodedArray=mLicenseTextStream.toByteArray();
      GZIPInputStream gis=new GZIPInputStream(new ByteArrayInputStream(encodedArray));
      byte[] decodedBuffer=new byte[128 * 1024];
      while (true) {
        int length=gis.read(decodedBuffer);
        if (length < 1) {
          SharedPreferences.Editor editor=PreferenceManager.getDefaultSharedPreferences(this).edit();
          editor.putString(Preferences.PREF_LICENSE_TEXT,mLicenseText);
          editor.commit();
          mLicenseText="";
          break;
        }
        mLicenseText=mLicenseText + new String(decodedBuffer,0,length,"utf-8");
      }
    }
 catch (    IOException e) {
      Log.i(ADK.TAG,"error = " + e.toString());
    }
  }
}
 

Example 39

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

Source file: BARCFile.java

  31 
vote

private void openInputStream() throws IOException {
  if (_in == null) {
    int len=_length;
    if (len >= 2)     len-=2;
    _in=new RecordInputStream(_offset + HEADER_LENGTH,len);
    if (_compressed && len > 0) {
      _in=new GZIPInputStream(_in,BUFFER_SIZE);
    }
    _metaHeadBytes=readHeaderBlock(_metaHeaderLength);
    _rqstHeadBytes=readHeaderBlock(_rqstHeaderLength);
    _respHeadBytes=readHeaderBlock(_respHeaderLength);
  }
}
 

Example 40

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

Source file: BinarySerializer.java

  31 
vote

@Override public final <T>T deserialize(String o,Class<T> targetType) throws SerializerException {
  try {
    ByteArrayInputStream bais=new ByteArrayInputStream(B64Code.decode(o));
    return targetType.cast(read(gzip ? new GZIPInputStream(bais) : bais));
  }
 catch (  Exception e) {
    throw new SerializerException("Error deserializing " + o + " : "+ e.getMessage(),e);
  }
}
 

Example 41

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

Source file: Utility.java

  31 
vote

/** 
 * Decode a string back to a byte array.
 * @param s the string to convert
 * @param uncompress use gzip to uncompress the stream of bytes
 */
public static byte[] decode(String s,boolean uncompress) throws IOException {
  char[] chars=s.toCharArray();
  CharArrayReader car=new CharArrayReader(chars);
  JavaReader jr=new JavaReader(car);
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  int ch;
  while ((ch=jr.read()) >= 0) {
    bos.write(ch);
  }
  bos.close();
  car.close();
  jr.close();
  byte[] bytes=bos.toByteArray();
  if (uncompress) {
    GZIPInputStream gis=new GZIPInputStream(new ByteArrayInputStream(bytes));
    byte[] tmp=new byte[bytes.length * 3];
    int count=0;
    int b;
    while ((b=gis.read()) >= 0) {
      tmp[count++]=(byte)b;
    }
    bytes=new byte[count];
    System.arraycopy(tmp,0,bytes,0,count);
  }
  return bytes;
}
 

Example 42

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

Source file: PROCore.java

  31 
vote

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

Example 43

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

Source file: GZip.java

  31 
vote

/** 
 * @param data
 * @return
 */
public static final byte[] decompress(byte[] data){
  ByteArrayOutputStream buffer=null;
  GZIPInputStream gizpInputStream=null;
  try {
    buffer=new ByteArrayOutputStream();
    gizpInputStream=new GZIPInputStream(new ByteArrayInputStream(data));
    int n=-1;
    @SuppressWarnings("unused") int tot=0;
    byte[] _buffer=new byte[1024 * 12];
    while (-1 != (n=gizpInputStream.read(_buffer))) {
      buffer.write(_buffer,0,n);
      tot+=n;
    }
    gizpInputStream.close();
    buffer.close();
  }
 catch (  IOException e) {
    throw new RuntimeException("Failed to GZip decompress data",e);
  }
  return buffer.toByteArray();
}
 

Example 44

From project k-9, under directory /src/com/fsck/k9/mail/store/.

Source file: WebDavStore.java

  31 
vote

public static InputStream getUngzippedContent(HttpEntity entity) throws IOException {
  InputStream responseStream=entity.getContent();
  if (responseStream == null)   return responseStream;
  Header header=entity.getContentEncoding();
  if (header == null)   return responseStream;
  String contentEncoding=header.getValue();
  if (contentEncoding == null)   return responseStream;
  if (contentEncoding.contains("gzip")) {
    Log.i(K9.LOG_TAG,"Response is gzipped");
    responseStream=new GZIPInputStream(responseStream);
  }
  return responseStream;
}
 

Example 45

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 46

From project mavuno, under directory /src/edu/isi/mavuno/nlp/.

Source file: NLProcTools.java

  31 
vote

public void initializePOSTagger() throws IOException, ClassNotFoundException {
  InputStream is=new GZIPInputStream(getClass().getClassLoader().getResourceAsStream(DEFAULT_TRATZ_POS_MODEL));
  ObjectInputStream ois=new ObjectInputStream(is);
  LinearClassificationModel model=(LinearClassificationModel)ois.readObject();
  PosFeatureGenerator featGenerator=(PosFeatureGenerator)ois.readObject();
  ois.close();
  mPosTagger=new PosTagger(model,featGenerator);
}
 

Example 47

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

Source file: XMLElement.java

  31 
vote

/** 
 * Simplified method to open a Java InputStream. <P> This method is useful if you want to use the facilities provided by PApplet to easily open things from the data folder or from a URL, but want an InputStream object so that you can use other Java methods to take more control of how the stream is read. <P> If the requested item doesn't exist, null is returned. (Prior to 0096, die() would be called, killing the applet) <P> For 0096+, the "data" folder is exported intact with subfolders, and openStream() properly handles subdirectories from the data folder <P> If not online, this will also check to see if the user is asking for a file whose name isn't properly capitalized. This helps prevent issues when a sketch is exported to the web, where case sensitivity matters, as opposed to Windows and the Mac OS default where case sensitivity is preserved but ignored. <P> It is strongly recommended that libraries use this method to open data files, so that the loading sequence is handled in the same way as functions like loadBytes(), loadImage(), etc. <P> The filename passed in can be: <UL> <LI>A URL, for instance openStream("http://processing.org/"); <LI>A file in the sketch's data folder <LI>Another file to be opened locally (when running as an application) </UL>
 */
public InputStream createInput(String filename){
  InputStream input=createInputRaw(filename);
  if ((input != null) && filename.toLowerCase().endsWith(".gz")) {
    try {
      return new GZIPInputStream(input);
    }
 catch (    IOException e) {
      e.printStackTrace();
      return null;
    }
  }
  return input;
}
 

Example 48

From project mdk, under directory /service/core/src/main/java/uk/ac/ebi/mdk/service/loader/location/.

Source file: GZIPRemoteLocation.java

  31 
vote

/** 
 * Open a gzip stream to the remote resource. This first opens the URLConnection and then the stream
 * @inheritDoc
 */
public InputStream open() throws IOException {
  if (stream == null) {
    stream=new GZIPInputStream(super.open());
  }
  return stream;
}
 

Example 49

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

Source file: IntegrationUtils.java

  31 
vote

public static byte[] decompress(byte[] contentBytes){
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  try {
    GZIPInputStream bis=new GZIPInputStream(new Base64InputStream(new ByteArrayInputStream(contentBytes)));
    byte[] buffer=new byte[1024 * 4];
    int n=0;
    while (-1 != (n=bis.read(buffer))) {
      out.write(buffer,0,n);
    }
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  return out.toByteArray();
}
 

Example 50

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

Source file: Utils.java

  31 
vote

/** 
 * Open a file and apply filters necessary for reading it such as decompression.
 * @param name The file to open.
 * @return A stream that will read the file, positioned at the beginning.
 * @throws FileNotFoundException If the file cannot be opened for any reason.
 */
public static InputStream openFile(String name) throws FileNotFoundException {
  InputStream is=new FileInputStream(name);
  if (name.endsWith(".gz")) {
    try {
      is=new GZIPInputStream(is);
    }
 catch (    IOException e) {
      throw new FileNotFoundException("Could not read as compressed file");
    }
  }
  return is;
}
 

Example 51

From project NFCShopping, under directory /mobile phone client/NFCShopping/src/weibo4android/http/.

Source file: Response.java

  31 
vote

public Response(HttpURLConnection con) throws IOException {
  this.con=con;
  this.statusCode=con.getResponseCode();
  if (null == (is=con.getErrorStream())) {
    is=con.getInputStream();
  }
  if (null != is && "gzip".equals(con.getContentEncoding())) {
    is=new GZIPInputStream(is);
  }
}
 

Example 52

From project obpro_team_p, under directory /twitter/twitter4j-core/src/main/java/twitter4j/internal/http/.

Source file: HttpResponseImpl.java

  31 
vote

HttpResponseImpl(HttpURLConnection con,HttpClientConfiguration conf) throws IOException {
  super(conf);
  this.con=con;
  this.statusCode=con.getResponseCode();
  if (null == (is=con.getErrorStream())) {
    is=con.getInputStream();
  }
  if (is != null && "gzip".equals(con.getContentEncoding())) {
    is=new GZIPInputStream(is);
  }
}
 

Example 53

From project Opal, under directory /opal-struct/src/main/java/com/lyndir/lhunath/opal/network/.

Source file: GZIPPostMethod.java

  31 
vote

/** 
 * If the response body was GZIP-compressed, responseStream will be set to a GZIPInputStream wrapping the original InputStream used by the super class. {@inheritDoc}
 */
@Override protected void readResponse(final HttpState state,final HttpConnection conn) throws IOException {
  super.readResponse(state,conn);
  Header contentEncodingHeader=getResponseHeader("Content-Encoding");
  if (contentEncodingHeader != null && "gzip".equalsIgnoreCase(contentEncodingHeader.getValue())) {
    InputStream zippedStream=new GZIPInputStream(getResponseStream());
    try {
      setResponseStream(zippedStream);
    }
  finally {
      Closeables.closeQuietly(zippedStream);
    }
  }
}
 

Example 54

From project OpenTripPlanner, under directory /opentripplanner-graph-builder/src/test/java/org/opentripplanner/graph_builder/impl/osm/.

Source file: OpenStreetMapParserTest.java

  31 
vote

@Test public void testBasicParser() throws Exception {
  InputStream in=new GZIPInputStream(getClass().getResourceAsStream("map.osm.gz"));
  OpenStreetMapParser parser=new OpenStreetMapParser();
  OSMMap map=new OSMMap();
  parser.parseMap(in,map);
  testParser(map);
}
 

Example 55

From project opentsdb, under directory /src/tools/.

Source file: TextImporter.java

  31 
vote

/** 
 * Opens a file for reading, handling gzipped files.
 * @param path The file to open.
 * @return A buffered reader to read the file, decompressing it if needed.
 * @throws IOException when shit happens.
 */
private static BufferedReader open(final String path) throws IOException {
  InputStream is=new FileInputStream(path);
  if (path.endsWith(".gz")) {
    is=new GZIPInputStream(is);
  }
  return new BufferedReader(new InputStreamReader(is));
}
 

Example 56

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

Source file: Message.java

  31 
vote

/** 
 * getContent returns the message body that accompanied the request. if the message was read from an InputStream, it reads the content from the InputStream and returns a copy of it. If the message body was chunked, or gzipped (according to the headers) it returns the unchunked and unzipped content.
 * @return Returns a byte array containing the message body
 */
public byte[] getContent(){
  try {
    flushContentStream(null);
  }
 catch (  IOException ioe) {
    _logger.info("IOException flushing the contentStream: " + ioe);
  }
  if (_content != null && _gzipped) {
    try {
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      GZIPInputStream gzis=new GZIPInputStream(new ByteArrayInputStream(_content.toByteArray()));
      byte[] buff=new byte[1024];
      int got;
      while ((got=gzis.read(buff)) > -1) {
        baos.write(buff,0,got);
      }
      return baos.toByteArray();
    }
 catch (    IOException ioe) {
      _logger.info("IOException unzipping content : " + ioe);
      return NO_CONTENT;
    }
  }
  if (_content != null) {
    return _content.toByteArray();
  }
 else {
    return NO_CONTENT;
  }
}
 

Example 57

From project Pdf4Eclipse, under directory /de.vonloesch.pdf4eclipse/src/de/vonloesch/pdf4eclipse/editors/.

Source file: PDFEditor.java

  31 
vote

private SimpleSynctexParser createSimpleSynctexParser(File f) throws IOException {
  InputStream in;
  if (f.getName().toLowerCase().endsWith(".gz")) {
    in=new GZIPInputStream(new FileInputStream(f));
  }
 else {
    in=new FileInputStream(f);
  }
  BufferedReader r=new BufferedReader(new InputStreamReader(in));
  return new SimpleSynctexParser(r);
}
 

Example 58

From project platform_packages_apps_browser, under directory /src/com/android/browser/.

Source file: SnapshotTab.java

  31 
vote

@Override protected void onPostExecute(Cursor result){
  try {
    if (result.moveToFirst()) {
      mTab.mCurrentState.mTitle=result.getString(SNAPSHOT_TITLE);
      mTab.mCurrentState.mUrl=result.getString(SNAPSHOT_URL);
      byte[] favicon=result.getBlob(SNAPSHOT_FAVICON);
      if (favicon != null) {
        mTab.mCurrentState.mFavicon=BitmapFactory.decodeByteArray(favicon,0,favicon.length);
      }
      WebViewClassic web=mTab.getWebViewClassic();
      if (web != null) {
        InputStream ins=getInputStream(result);
        GZIPInputStream stream=new GZIPInputStream(ins);
        web.loadViewState(stream);
      }
      mTab.mBackgroundColor=result.getInt(SNAPSHOT_BACKGROUND);
      mTab.mDateCreated=result.getLong(SNAPSHOT_DATE_CREATED);
      mTab.mWebViewController.onPageFinished(mTab);
    }
  }
 catch (  Exception e) {
    Log.w(LOGTAG,"Failed to load view state, closing tab",e);
    mTab.mWebViewController.closeTab(mTab);
  }
 finally {
    if (result != null) {
      result.close();
    }
    mTab.mLoadTask=null;
  }
}
 

Example 59

From project playn, under directory /core/tests/playn/core/json/.

Source file: InternalJsonParserTest.java

  31 
vote

@Test public void tortureTest() throws JsonParserException, IOException {
  InputStream input=getClass().getResourceAsStream("torturetest.json.gz");
  JsonObject o=JsonParser.object().from(readAsUtf8(new GZIPInputStream(input)));
  assertNotNull(o.get("a"));
  assertNotNull(o.getObject("a").getArray("b\uecee\u8324\u007a\\\ue768.N"));
  String json=new JsonStringWriter().object(o).write();
  JsonObject o2=JsonParser.object().from(json);
  new JsonStringWriter().object(o2).write();
}
 

Example 60

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

Source file: GZipUnArchiver.java

  31 
vote

protected void execute() throws ArchiverException {
  if (getSourceFile().lastModified() > getDestFile().lastModified()) {
    getLogger().info("Expanding " + getSourceFile().getAbsolutePath() + " to "+ getDestFile().getAbsolutePath());
    FileOutputStream out=null;
    GZIPInputStream zIn=null;
    FileInputStream fis=null;
    try {
      out=new FileOutputStream(getDestFile());
      fis=new FileInputStream(getSourceFile());
      zIn=new GZIPInputStream(fis);
      byte[] buffer=new byte[8 * 1024];
      int count=0;
      do {
        out.write(buffer,0,count);
        count=zIn.read(buffer,0,buffer.length);
      }
 while (count != -1);
    }
 catch (    IOException ioe) {
      String msg="Problem expanding gzip " + ioe.getMessage();
      throw new ArchiverException(msg,ioe);
    }
 finally {
      IOUtil.close(fis);
      IOUtil.close(out);
      IOUtil.close(zIn);
    }
  }
}
 

Example 61

From project PocketVDC, under directory /src/sate/pocketvdc/rendering/.

Source file: PocketVDCRenderer.java

  31 
vote

/** 
 * @param base64String
 * @param textureSize The size, in bytes, of the uncompressed, raw texture data
 * @return texture handle for new texture
 */
private int loadBase64GzipRGBATexture(String base64String,int textureSize){
  final int[] textureHandle=new int[1];
  GLES20.glGenTextures(1,textureHandle,0);
  if (textureHandle[0] != 0) {
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureHandle[0]);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MIN_FILTER,GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_REPEAT);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_REPEAT);
    try {
      GZIPInputStream gzip=new GZIPInputStream(new ByteArrayInputStream(android.util.Base64.decode(base64String,Base64.DEFAULT)));
      if (textureSize < 1048576) {
        textureSize=1048576;
      }
      byte[] buffer=new byte[textureSize + 10000];
      int readBytes=0;
      int offset=0;
      while ((readBytes=gzip.read(buffer,offset,buffer.length - offset)) > 0) {
        offset+=readBytes;
      }
      Log.d("PocketVDCRenderer","read " + offset + " total bytes.");
      ByteBuffer pixels=ByteBuffer.wrap(buffer);
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,0,GLES20.GL_RGBA,512,512,0,GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE,pixels);
      gzip.close();
      pixels.clear();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
  if (textureHandle[0] == 0) {
    throw new RuntimeException("Error loading texture.");
  }
  return textureHandle[0];
}
 

Example 62

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

Source file: GA.java

  31 
vote

public static GA GAWithCheckpoint(String checkpoint) throws Exception {
  File checkpointFile=new File(checkpoint);
  FileInputStream zin=new FileInputStream(checkpointFile);
  GZIPInputStream in=new GZIPInputStream(zin);
  ObjectInputStream oin=new ObjectInputStream(in);
  Checkpoint ckpt=(Checkpoint)oin.readObject();
  GA ga=ckpt.ga;
  ga._checkpoint=ckpt;
  ckpt.checkpointNumber++;
  oin.close();
  System.out.println(ckpt.report.toString());
  if (ga._outputfile != null)   ga._outputStream=new FileOutputStream(new File(ga._outputfile));
 else   ga._outputStream=System.out;
  return ga;
}
 

Example 63

From project rapid, under directory /rapid-generator/rapid-generator/src/main/java/cn/org/rapid_framework/generator/util/paranamer/.

Source file: JavadocParanamer.java

  31 
vote

private InputStream urlToInputStream(URL url) throws IOException {
  URLConnection conn=url.openConnection();
  conn.setRequestProperty("User-Agent",IE);
  conn.setRequestProperty("Accept-Encoding","gzip, deflate");
  conn.connect();
  String encoding=conn.getContentEncoding();
  if ((encoding != null) && encoding.equalsIgnoreCase("gzip"))   return new GZIPInputStream(conn.getInputStream());
 else   if ((encoding != null) && encoding.equalsIgnoreCase("deflate"))   return new InflaterInputStream(conn.getInputStream(),new Inflater(true));
 else   return conn.getInputStream();
}
 

Example 64

From project recommenders, under directory /tests/org.eclipse.recommenders.tests.completion.rcp/src/org/eclipse/recommenders/tests/completion/rcp/calls/.

Source file: ModelLoadingTest.java

  31 
vote

@BeforeClass public static void beforeClass() throws IOException, ClassNotFoundException {
  Stopwatch w=new Stopwatch();
  w.start();
  String pkg=ModelLoadingTest.class.getPackage().getName().replace('.','/') + "/Text.data.gz_";
  InputStream s=ModelLoadingTest.class.getClassLoader().getResourceAsStream(pkg);
  InputStream is=new GZIPInputStream(s);
  ObjectInputStream ois=new ObjectInputStream(is);
  BayesianNetwork net=(BayesianNetwork)ois.readObject();
  sut=new BayesNetWrapper(VmTypeName.BYTE,net);
  w.stop();
  System.out.println("loading model took: " + w);
}
 

Example 65

From project rozkladpkp-android, under directory /src/org/tyszecki/rozkladpkp/servers/.

Source file: HafasServer.java

  31 
vote

public int getConnections(ArrayList<SerializableNameValuePair> data,String ld){
  data=prepareFields(data);
  DefaultHttpClient client=new DefaultHttpClient();
  HttpPost request=new HttpPost(url(URL_CONNECTIONS) + ((ld == null) ? "" : "?ld=" + ld));
  client.removeRequestInterceptorByClass(org.apache.http.protocol.RequestExpectContinue.class);
  client.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class);
  for (int i=0; i < data.size(); ++i) {
    Log.i("RozkladPKP",data.get(i).getName() + "=" + data.get(i).getValue());
  }
  request.addHeader("Content-Type","text/plain");
  try {
    request.setEntity(new UrlEncodedFormEntity(data,"UTF-8"));
  }
 catch (  UnsupportedEncodingException e) {
    return DOWNLOAD_ERROR_OTHER;
  }
  ByteArrayOutputStream content=new ByteArrayOutputStream();
  HttpResponse response;
  try {
    response=client.execute(request);
    HttpEntity entity=response.getEntity();
    InputStream inputStream=entity.getContent();
    GZIPInputStream in=new GZIPInputStream(inputStream);
    int readBytes=0;
    while ((readBytes=in.read(sBuffer)) != -1) {
      content.write(sBuffer,0,readBytes);
    }
  }
 catch (  Exception e) {
    return DOWNLOAD_ERROR_SERVER_FAULT;
  }
  try {
    pln=new PLN(content.toByteArray());
  }
 catch (  Exception e) {
    return DOWNLOAD_ERROR_SERVER_FAULT;
  }
  if (ld == null || pln.conCnt > 0)   return DOWNLOAD_OK;
  return DOWNLOAD_ERROR_WAIT;
}
 

Example 66

From project s4, under directory /s4-examples/twittertopiccount-ft/src/main/java/org/apache/s4/example/twittertopiccount/.

Source file: TwitterFeedReader.java

  31 
vote

@Override public void connectAndRead() throws Exception {
  System.out.println("Reading files from dir " + twitterDumpsDir + " matching: "+ twitterDumpsNamePattern);
  File[] dumps=new File(twitterDumpsDir).listFiles(new FilenameFilter(){
    @Override public boolean accept(    File dir,    String name){
      return name.matches(twitterDumpsNamePattern);
    }
  }
);
  for (  File dump : dumps) {
    System.out.println("Reading file : " + dump.getAbsolutePath());
    GZIPInputStream gzipIs=new GZIPInputStream(new FileInputStream(dump));
    InputStreamReader isr=new InputStreamReader(gzipIs);
    BufferedReader br=new BufferedReader(isr);
    String line=null;
    while ((line=br.readLine()) != null) {
      if (line.startsWith("{")) {
        messageQueue.add(line);
        Thread.sleep((1000 / Integer.valueOf(frequencyBySecond)));
      }
    }
    br.close();
  }
  System.out.println("OK, read all dump files. Exiting normally.");
  System.exit(0);
}
 

Example 67

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

Source file: SenseiGenericBPOConverter.java

  31 
vote

public static byte[] decompress(byte[] output) throws IOException {
  ByteArrayInputStream bais=new ByteArrayInputStream(output);
  GZIPInputStream gzis=new GZIPInputStream(bais);
  byte[] buf=new byte[2048];
  List<byte[]> list=new LinkedList<byte[]>();
  int len=gzis.read(buf,0,2048);
  int i=0;
  while (len > 0) {
    byte[] b1=new byte[len];
    System.arraycopy(buf,0,b1,0,len);
    list.add(b1);
    i+=len;
    len=gzis.read(buf,0,2048);
  }
  gzis.close();
  byte[] whole=new byte[i];
  int start=0;
  for (  byte[] part : list) {
    System.arraycopy(part,0,whole,start,part.length);
    start+=part.length;
  }
  return whole;
}
 

Example 68

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

Source file: GZip.java

  31 
vote

public static String decodeWithGZip(byte[] bytes){
  try {
    GZIPInputStream gzipInputStream=new GZIPInputStream(new ByteArrayInputStream(bytes));
    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(gzipInputStream));
    StringWriter stringWriter=new StringWriter();
    String s=null;
    while ((s=bufferedReader.readLine()) != null) {
      stringWriter.write(s);
    }
    bufferedReader.close();
    String result=stringWriter.toString();
    stringWriter.close();
    return result;
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return new String(bytes);
}
 

Example 69

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

Source file: PersistentCachedMap.java

  31 
vote

/** 
 * Get a mapping back from the persisted storage.
 * @param key the key for the mapping
 * @return the value of the mapping
 */
protected Object recoverObject(final Object key){
  try {
    FileInputStream fIn=new FileInputStream(path + key + ".data");
    GZIPInputStream gzFIn=new GZIPInputStream(fIn);
    ObjectInputStream objIn=new ObjectInputStream(gzFIn);
    Object obj=objIn.readObject();
    gzFIn.close();
    objIn.close();
    return obj;
  }
 catch (  Exception e) {
    toc.remove(key.toString());
    e.printStackTrace();
    throw new RuntimeException("Can't read" + path + "-"+ key+ ".data, did u erase it manually?");
  }
}
 

Example 70

From project Sketchy-Truck, under directory /andengine/src/org/anddev/andengine/opengl/texture/compressed/pvr/.

Source file: PVRCCZTexture.java

  31 
vote

public InputStream wrap(final InputStream pInputStream) throws IOException {
switch (this) {
case GZIP:
    return new GZIPInputStream(pInputStream);
case ZLIB:
  return new InflaterInputStream(pInputStream,new Inflater());
case NONE:
case BZIP2:
default :
throw new IllegalArgumentException("Unexpected " + CCZCompressionFormat.class.getSimpleName() + ": '"+ this+ "'.");
}
}
 

Example 71

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

Source file: Document.java

  31 
vote

public static Document load(File file) throws IOException {
  InputStream in=new GZIPInputStream(new BufferedInputStream(new FileInputStream(file)));
  try {
    Document result=loadFrom(in);
    result.setLocation(file);
    return result;
  }
 catch (  JAXBException e) {
    throw new RuntimeException(e);
  }
 finally {
    Utilities.close(in);
  }
}
 

Example 72

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

Source file: VersionedCache.java

  31 
vote

/** 
 * Decompress the given array of bytes.
 * @return null if the bytes cannot be decompressed
 */
protected static byte[] decompress(byte[] in){
  ByteArrayOutputStream bos=null;
  if (in != null) {
    ByteArrayInputStream bis=new ByteArrayInputStream(in);
    bos=new ByteArrayOutputStream();
    GZIPInputStream gis=null;
    try {
      gis=new GZIPInputStream(bis);
      byte[] buf=new byte[16 * 1024];
      int r=-1;
      while ((r=gis.read(buf)) > 0) {
        bos.write(buf,0,r);
      }
    }
 catch (    IOException e) {
      log.error("Failed to decompress data",e);
      bos=null;
    }
 finally {
      if (gis != null) {
        try {
          gis.close();
        }
 catch (        IOException e) {
          log.error("Close GZIPInputStream error",e);
        }
      }
      if (bis != null) {
        try {
          bis.close();
        }
 catch (        IOException e) {
          log.error("Close ByteArrayInputStream error",e);
        }
      }
    }
  }
  return bos == null ? null : bos.toByteArray();
}
 

Example 73

From project android_7, under directory /src/org/immopoly/android/helper/.

Source file: WebHelper.java

  30 
vote

public static JSONArray postFlatIdsHttpData(String url,JSONObject jsonObject) throws JSONException {
  try {
    InputStream in;
    HttpResponse response=postHttp(url,jsonObject);
    Header contentEncoding=response.getFirstHeader("Content-Encoding");
    if (response != null && contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
      in=new GZIPInputStream(response.getEntity().getContent());
    }
 else {
      in=new BufferedInputStream(response.getEntity().getContent());
    }
    String s=readInputStream(in);
    return new JSONArray(s);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 74

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/.

Source file: EasResponse.java

  30 
vote

/** 
 * Return an appropriate input stream for the response, either a GZIPInputStream, for compressed data, or a generic InputStream otherwise
 * @return the input stream for the response
 */
public InputStream getInputStream(){
  if (mInputStream != null || mClosed) {
    throw new IllegalStateException("Can't reuse stream or get closed stream");
  }
 else   if (mEntity == null) {
    throw new IllegalStateException("Can't get input stream without entity");
  }
  InputStream is=null;
  try {
    is=mEntity.getContent();
    Header ceHeader=mResponse.getFirstHeader("Content-Encoding");
    if (ceHeader != null) {
      String encoding=ceHeader.getValue();
      if (encoding.toLowerCase().equals("gzip")) {
        is=new GZIPInputStream(is);
      }
    }
  }
 catch (  IllegalStateException e1) {
  }
catch (  IOException e1) {
  }
  mInputStream=is;
  return is;
}
 

Example 75

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

Source file: GzipCompressor.java

  30 
vote

@Override public byte[] decompress(byte[] value,int offset,int length) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream(MathUtils.nextPowOfTwo(2 * length));
  try (ByteArrayInputStream bais=new ByteArrayInputStream(value,offset,length)){
    try (InputStream in=new GZIPInputStream(bais)){
      byte[] buffer=new byte[Math.min(length,1024)];
      int len=-1;
      while ((len=in.read(buffer)) != -1) {
        baos.write(buffer,0,len);
      }
    }
   }
  finally {
    IoUtils.close(baos);
  }
  return baos.toByteArray();
}
 

Example 76

From project babel, under directory /src/babel/content/eqclasses/phrases/.

Source file: PhraseSet.java

  30 
vote

protected void processPhraseListFile(String phrasesFile,String encoding,boolean caseSensitive,int maxPhraseLength) throws IOException {
  InputStream is=new FileInputStream(phrasesFile);
  if (phrasesFile.toLowerCase().endsWith("gz")) {
    is=new GZIPInputStream(is);
  }
  BufferedReader fileReader=new BufferedReader(new InputStreamReader(is,encoding));
  String line=null;
  Phrase phrase;
  while ((line=fileReader.readLine()) != null) {
    (phrase=new Phrase()).init(line,caseSensitive);
    if (((maxPhraseLength < 0) || (phrase.numTokens() <= maxPhraseLength)) && !m_phrases.contains(phrase)) {
      phrase.assignId();
      m_phrases.add(phrase);
    }
  }
  fileReader.close();
}
 

Example 77

From project boilerpipe_1, under directory /boilerpipe-core/src/main/de/l3s/boilerpipe/sax/.

Source file: HTMLFetcher.java

  30 
vote

/** 
 * Fetches the document at the given URL, using  {@link URLConnection}.
 * @param url
 * @return
 * @throws IOException
 */
public static HTMLDocument fetch(final URL url) throws IOException {
  final URLConnection conn=url.openConnection();
  final String ct=conn.getContentType();
  Charset cs=Charset.forName("Cp1252");
  if (ct != null) {
    Matcher m=PAT_CHARSET.matcher(ct);
    if (m.find()) {
      final String charset=m.group(1);
      try {
        cs=Charset.forName(charset);
      }
 catch (      UnsupportedCharsetException e) {
      }
    }
  }
  InputStream in=conn.getInputStream();
  final String encoding=conn.getContentEncoding();
  if (encoding != null) {
    if ("gzip".equalsIgnoreCase(encoding)) {
      in=new GZIPInputStream(in);
    }
 else {
      System.err.println("WARN: unsupported Content-Encoding: " + encoding);
    }
  }
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  byte[] buf=new byte[4096];
  int r;
  while ((r=in.read(buf)) != -1) {
    bos.write(buf,0,r);
  }
  in.close();
  final byte[] data=bos.toByteArray();
  return new HTMLDocument(data,cs);
}
 

Example 78

From project ChkBugReport, under directory /src/com/sonyericsson/chkbugreport/.

Source file: Main.java

  30 
vote

private boolean loadFrom(Module report,String fileName,InputStream is){
  is=new BufferedInputStream(is,0x1000);
  try {
    is.mark(0x100);
    is=new GZIPInputStream(is);
  }
 catch (  IOException e) {
    try {
      is.reset();
    }
 catch (    IOException e1) {
      e1.printStackTrace();
    }
  }
  try {
    report.load(is);
    return true;
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
}
 

Example 79

From project cp-common-utils, under directory /src/com/clarkparsia/common/web/.

Source file: Response.java

  30 
vote

public Response(final HttpURLConnection theConn,final Collection<Header> theHeaders){
  mHeaders=new HashMap<String,Header>();
  for (  Header aHeader : theHeaders) {
    mHeaders.put(aHeader.getName(),aHeader);
  }
  mConnection=theConn;
  try {
    mContent=theConn.getInputStream();
    String contentEncoding=theConn.getContentEncoding();
    if ("gzip".equals(contentEncoding)) {
      mContent=new GZIPInputStream(mContent);
    }
  }
 catch (  IOException e) {
  }
  try {
    mErrorStream=theConn.getErrorStream();
  }
 catch (  Exception e) {
  }
  try {
    mMessage=theConn.getResponseMessage();
  }
 catch (  IOException e) {
  }
  try {
    mResponseCode=theConn.getResponseCode();
  }
 catch (  IOException e) {
    mResponseCode=-1;
  }
}
 

Example 80

From project droidparts, under directory /extra/src/org/droidparts/http/wrapper/.

Source file: DefaultHttpClientWrapper.java

  30 
vote

public static InputStream getUnpackedInputStream(HttpEntity entity) throws HTTPException {
  try {
    InputStream is=entity.getContent();
    Header contentEncodingHeader=entity.getContentEncoding();
    L.d(contentEncodingHeader);
    if (contentEncodingHeader != null) {
      String contentEncoding=contentEncodingHeader.getValue();
      if (!isEmpty(contentEncoding)) {
        contentEncoding=contentEncoding.toLowerCase();
        if (contentEncoding.contains("gzip")) {
          return new GZIPInputStream(is);
        }
 else         if (contentEncoding.contains("deflate")) {
          return new InflaterInputStream(is);
        }
      }
    }
    return is;
  }
 catch (  Exception e) {
    throw new HTTPException(e);
  }
}
 

Example 81

From project enclojure, under directory /org-enclojure-ide/src/main/java/org/enclojure/ide/asm/optimizer/.

Source file: JarOptimizer.java

  30 
vote

public static void main(final String[] args) throws IOException {
  File f=new File(args[0]);
  InputStream is=new GZIPInputStream(new FileInputStream(f));
  BufferedReader lnr=new LineNumberReader(new InputStreamReader(is));
  while (true) {
    String line=lnr.readLine();
    if (line != null) {
      if (line.startsWith("class")) {
        String c=line.substring(6,line.lastIndexOf(' '));
        String sc=line.substring(line.lastIndexOf(' ') + 1);
        HIERARCHY.put(c,sc);
      }
 else {
        API.add(line);
      }
    }
 else {
      break;
    }
  }
  optimize(new File(args[1]));
}
 

Example 82

From project eoit, under directory /EOIT/src/fr/eoit/util/.

Source file: AndroidUrlDownloader.java

  30 
vote

@Override public InputStream urlToInputStream(String url) throws DownloadException {
  try {
    HttpClient httpclient=new DefaultHttpClient();
    HttpGet httpget=new HttpGet(url);
    httpget.addHeader("Accept-Encoding","gzip");
    HttpResponse response;
    response=httpclient.execute(httpget);
    Log.v(LOG_TAG,response.getStatusLine().toString());
    HttpEntity entity=response.getEntity();
    if (entity != null) {
      InputStream instream=entity.getContent();
      Header contentEncoding=response.getFirstHeader("Content-Encoding");
      if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
        Log.v(LOG_TAG,"Accepting gzip for url : " + url);
        instream=new GZIPInputStream(instream);
      }
      return instream;
    }
  }
 catch (  IllegalStateException e) {
    throw new DownloadException(e);
  }
catch (  IOException e) {
    throw new DownloadException(e);
  }
  return null;
}
 

Example 83

From project gnip4j, under directory /core/src/main/java/com/zaubersoftware/gnip4j/api/support/http/.

Source file: JRERemoteResourceProvider.java

  30 
vote

@Override public final InputStream getResource(final URI uri) throws AuthenticationGnipException, TransportGnipException {
  try {
    final URLConnection uc=uri.toURL().openConnection();
    HttpURLConnection huc=null;
    if (uc instanceof HttpURLConnection) {
      huc=(HttpURLConnection)uc;
    }
    uc.setAllowUserInteraction(false);
    uc.setDefaultUseCaches(false);
    uc.setConnectTimeout(connectTimeout);
    uc.setReadTimeout(readTimeout);
    uc.setRequestProperty("Accept-Encoding","gzip, deflate");
    uc.setRequestProperty("User-Agent",USER_AGENT);
    uc.setRequestProperty("Authorization","Basic " + encoder.encode(authentication));
    doConfiguration(uc);
    uc.connect();
    if (huc != null) {
      validateStatusLine(uri,huc.getResponseCode(),huc.getResponseMessage());
    }
    InputStream is=uc.getInputStream();
    final String encoding=uc.getContentEncoding();
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
      is=new GZIPInputStream(is);
    }
 else     if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
      is=new InflaterInputStream(is,new Inflater(true));
    }
    return new JREReleaseInputStream(uc,is);
  }
 catch (  final MalformedURLException e) {
    throw new TransportGnipException(e);
  }
catch (  final IOException e) {
    throw new TransportGnipException(e);
  }
}
 

Example 84

From project gxa, under directory /atlas-web/src/main/java/uk/ac/ebi/gxa/requesthandlers/wiggle/bam/.

Source file: BAMHeaderReader.java

  30 
vote

private void readInfo() throws IOException {
  chromosomeIndex=new HashMap<String,Integer>();
  chromosomeLength=new HashMap<String,Integer>();
  InputStream stream=null;
  try {
    stream=new GZIPInputStream(new FileInputStream(file));
    if (!"BAM\001".equals(FileTools.readString(stream,4))) {
      throw new BAMException("Invalid BAM file signature");
    }
    final int l_text=FileTools.readInt32(stream);
    FileTools.readString(stream,l_text);
    final int n_ref=FileTools.readInt32(stream);
    for (int i=0; i < n_ref; ++i) {
      final int l_name=FileTools.readInt32(stream);
      final String name=l_name > 0 ? FileTools.readString(stream,l_name).substring(0,l_name - 1) : "";
      final int l_ref=FileTools.readInt32(stream);
      chromosomeIndex.put(name,i);
      chromosomeLength.put(name,l_ref);
    }
  }
  finally {
    closeQuietly(stream);
  }
}
 

Example 85

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

Source file: EncodingUtil.java

  30 
vote

/** 
 * Decodes Base64 alphabet characters of the string <code>s</code>, decrypts this string and finally decompresses it.
 * @param s data to decrypt
 * @return decoded data
 * @throws HDIVException if there is an error decoding object <code>data</code>
 * @see org.apache.commons.codec.binary.Base64#decode(byte[])
 * @see org.apache.commons.codec.net.URLCodec#decode(byte[])
 * @see java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream)
 */
public Object decode64Cipher(String s){
  try {
    Base64 base64Codec=new Base64();
    byte[] encryptedData=base64Codec.decode(s.getBytes(ZIP_CHARSET));
    byte[] encodedData=URLCodec.decodeUrl(encryptedData);
    byte[] data=this.session.getDecryptCipher().decrypt(encodedData);
    ByteArrayInputStream decodedStream=new ByteArrayInputStream(data);
    InputStream unzippedStream=new GZIPInputStream(decodedStream);
    ObjectInputStream ois=new ObjectInputStream(unzippedStream);
    Object obj=ois.readObject();
    ois.close();
    unzippedStream.close();
    decodedStream.close();
    return obj;
  }
 catch (  Exception e) {
    throw new HDIVException(HDIVErrorCodes.HDIV_PARAMETER_INCORRECT_VALUE);
  }
}
 

Example 86

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 87

From project Jetwick, under directory /src/main/java/de/jetwick/util/.

Source file: Helper.java

  30 
vote

public static String[] getUrlInfos(String urlAsString,int timeout){
  try {
    URL url=new URL(urlAsString);
    HttpURLConnection hConn=(HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
    hConn.setRequestProperty("User-Agent","Mozilla/5.0 Gecko/20100915 Firefox/3.6.10");
    hConn.setConnectTimeout(timeout);
    hConn.setReadTimeout(timeout);
    byte[] arr=new byte[K4];
    InputStream is=hConn.getInputStream();
    if ("gzip".equals(hConn.getContentEncoding()))     is=new GZIPInputStream(is);
    BufferedInputStream in=new BufferedInputStream(is,arr.length);
    in.read(arr);
    return getUrlInfosFromText(arr,hConn.getContentType());
  }
 catch (  Exception ex) {
  }
  return new String[]{"",""};
}
 

Example 88

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

Source file: LogFile.java

  30 
vote

public LogFile(File file) throws FileNotFoundException, IOException {
  this.file=file;
  this.platform="";
  this.description="";
  deviceAlias=new HashMap<String,String>();
  String filename=file.getPath();
  if (filename.endsWith(".log.gz")) {
    compressed=true;
    inputStream=new GZIPInputStream(new FileInputStream(file));
  }
 else {
    compressed=false;
    inputStream=new FileInputStream(file);
  }
  parseHeader();
  findPositions();
}
 

Example 89

From project kevoree-library, under directory /javase/org.kevoree.library.javase.logger.greg/src/main/java/org/kevoree/library/logger/greg/.

Source file: GregRecordChannel.java

  30 
vote

private GregRecordsMessage processRecordsBatch(InputStream rawStream){
  try {
    InputStream stream=new BufferedInputStream(rawStream,65536);
    DataInput r=new LittleEndianDataInputStream(stream);
    UUID uuid=new UUID(r.readLong(),r.readLong());
    boolean useCompression=r.readBoolean();
    GregRecordsMessage msg=readRecords(useCompression ? new GZIPInputStream(stream) : stream);
    msg.setUuid(uuid);
    return msg;
  }
 catch (  Exception e) {
    Trace.writeLine("Failed to receive records batch, ignoring",e);
  }
  return null;
}
 

Example 90

From project kumvandroid, under directory /src/com/ijuru/kumva/search/.

Source file: OnlineSearch.java

  30 
vote

/** 
 * @see com.ijuru.kumva.search.Search#doSearch(String)
 */
@Override public SearchResult doSearch(String query,int limit){
  try {
    SAXParserFactory factory=SAXParserFactory.newInstance();
    SAXParser parser=factory.newSAXParser();
    QueryXMLHandler handler=new QueryXMLHandler();
    handler.addListener(this);
    URL url=dictionary.createQueryURL(query,limit);
    URLConnection connection=url.openConnection();
    connection.setRequestProperty("Accept-Encoding","gzip");
    connection.setConnectTimeout(timeout);
    connection.setReadTimeout(timeout);
    InputStream stream=connection.getInputStream();
    if ("gzip".equals(connection.getContentEncoding()))     stream=new GZIPInputStream(stream);
    InputSource source=new InputSource(stream);
    parser.parse(source,handler);
    stream.close();
    return new SearchResult(handler.getSuggestion(),results);
  }
 catch (  Exception e) {
    Log.e("Kumva",e.getMessage(),e);
    return null;
  }
}
 

Example 91

From project Lily, under directory /apps/mbox-import/src/main/java/org/lilyproject/tools/mboximport/.

Source file: MboxImport.java

  30 
vote

private void importFile(File file) throws Exception {
  System.out.println("Processing file " + file.getAbsolutePath());
  InputStream is=null;
  try {
    is=new FileInputStream(file);
    if (file.getName().endsWith(".gz")) {
      is=new GZIPInputStream(is);
    }
    MboxInputStream mboxStream=new MboxInputStream(is,MAX_LINE_LENGTH);
    while (mboxStream.nextMessage()) {
      MimeTokenStream stream=new MyMimeTokenStream();
      stream.parse(mboxStream);
      importMessage(stream);
    }
  }
  finally {
    Closer.close(is);
  }
  System.out.println();
}
 

Example 92

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

Source file: Serializer.java

  30 
vote

/** 
 * deserializes DBBinary/byte[] to object 
 */
public static Object deserialize(final Object data,final boolean zipped) throws IOException, ClassNotFoundException {
  ByteArrayInputStream bais;
  if (data instanceof Binary) {
    bais=new ByteArrayInputStream(((Binary)data).getData());
  }
 else {
    bais=new ByteArrayInputStream((byte[])data);
  }
  InputStream is=bais;
  try {
    if (zipped) {
      is=new GZIPInputStream(is);
    }
    final ObjectInputStream ois=new ObjectInputStream(is);
    return ois.readObject();
  }
  finally {
    is.close();
  }
}
 

Example 93

From project Notes, under directory /src/net/micode/notes/gtask/remote/.

Source file: GTaskClient.java

  30 
vote

private String getResponseContent(HttpEntity entity) throws IOException {
  String contentEncoding=null;
  if (entity.getContentEncoding() != null) {
    contentEncoding=entity.getContentEncoding().getValue();
    Log.d(TAG,"encoding: " + contentEncoding);
  }
  InputStream input=entity.getContent();
  if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
    input=new GZIPInputStream(entity.getContent());
  }
 else   if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
    Inflater inflater=new Inflater(true);
    input=new InflaterInputStream(entity.getContent(),inflater);
  }
  try {
    InputStreamReader isr=new InputStreamReader(input);
    BufferedReader br=new BufferedReader(isr);
    StringBuilder sb=new StringBuilder();
    while (true) {
      String buff=br.readLine();
      if (buff == null) {
        return sb.toString();
      }
      sb=sb.append(buff);
    }
  }
  finally {
    input.close();
  }
}
 

Example 94

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

Source file: AbstractModelReader.java

  30 
vote

public AbstractModelReader(File f) throws IOException {
  String filename=f.getName();
  InputStream input;
  if (filename.endsWith(".gz")) {
    input=new GZIPInputStream(new FileInputStream(f));
    filename=filename.substring(0,filename.length() - 3);
  }
 else {
    input=new FileInputStream(f);
  }
  if (filename.endsWith(".bin")) {
    this.dataReader=new BinaryFileDataReader(input);
  }
 else {
    this.dataReader=new PlainTextFileDataReader(input);
  }
}
 

Example 95

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

Source file: AbstractModelReader.java

  30 
vote

public AbstractModelReader(File f) throws IOException {
  String filename=f.getName();
  InputStream input;
  if (filename.endsWith(".gz")) {
    input=new GZIPInputStream(new FileInputStream(f));
    filename=filename.substring(0,filename.length() - 3);
  }
 else {
    input=new FileInputStream(f);
  }
  if (filename.endsWith(".bin")) {
    this.dataReader=new BinaryFileDataReader(input);
  }
 else {
    this.dataReader=new PlainTextFileDataReader(input);
  }
}
 

Example 96

From project pepe, under directory /pepe/src/edu/stanford/pepe/org/objectweb/asm/optimizer/.

Source file: JarOptimizer.java

  30 
vote

public static void main(final String[] args) throws IOException {
  File f=new File(args[0]);
  InputStream is=new GZIPInputStream(new FileInputStream(f));
  BufferedReader lnr=new LineNumberReader(new InputStreamReader(is));
  while (true) {
    String line=lnr.readLine();
    if (line != null) {
      if (line.startsWith("class")) {
        String c=line.substring(6,line.lastIndexOf(' '));
        String sc=line.substring(line.lastIndexOf(' ') + 1);
        HIERARCHY.put(c,sc);
      }
 else {
        API.add(line);
      }
    }
 else {
      break;
    }
  }
  optimize(new File(args[1]));
}
 

Example 97

From project QuakeInjector, under directory /src/de/haukerehfeld/quakeinjector/.

Source file: Download.java

  30 
vote

public InputStream getStream(ProgressListener progress) throws IOException {
  if (stream == null) {
    String encoding=connection.getContentEncoding();
    stream=connection.getInputStream();
    if (progress != null) {
      stream=new ProgressListenerInputStream(stream,progress);
    }
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
      stream=new GZIPInputStream(stream);
    }
 else     if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
      stream=new InflaterInputStream(stream,new Inflater(true));
    }
  }
  return stream;
}
 

Example 98

From project recordloader, under directory /src/java/com/marklogic/recordloader/.

Source file: DefaultInputHandler.java

  30 
vote

/** 
 * @throws IOException
 * @throws LoaderException
 */
private void handleGzFiles() throws IOException, LoaderException {
  if (null == gzFiles) {
    return;
  }
  File file;
  String name;
  String path;
  Iterator<File> iter=gzFiles.iterator();
  if (iter.hasNext()) {
    while (iter.hasNext()) {
      file=iter.next();
      name=file.getName();
      if (name.endsWith(".tar.gz") || name.endsWith(".tgz")) {
        logger.warning("skipping unsupported tar file " + file.getCanonicalPath());
        continue;
      }
      path=file.getPath();
      submit(path,factory.newLoader(new GZIPInputStream(new FileInputStream(file)),name,path));
    }
  }
}
 

Example 99

From project restfuse, under directory /com.eclipsesource.restfuse/src/com/github/kevinsawicki/http/.

Source file: HttpRequest.java

  30 
vote

/** 
 * Get stream to response body
 * @return stream
 * @throws HttpRequestException
 */
public InputStream stream() throws HttpRequestException {
  InputStream stream;
  if (code() < HTTP_BAD_REQUEST)   try {
    stream=connection.getInputStream();
  }
 catch (  IOException e) {
    throw new HttpRequestException(e);
  }
 else {
    stream=connection.getErrorStream();
    if (stream == null)     try {
      stream=connection.getInputStream();
    }
 catch (    IOException e) {
      throw new HttpRequestException(e);
    }
  }
  if (!uncompress || !ENCODING_GZIP.equals(contentEncoding()))   return stream;
 else   try {
    return new GZIPInputStream(stream);
  }
 catch (  IOException e) {
    throw new HttpRequestException(e);
  }
}
 

Example 100

From project Solbase-Solr, under directory /src/java/org/apache/solr/handler/.

Source file: SnapPuller.java

  30 
vote

private InputStream checkCompressed(HttpMethod method,InputStream respBody) throws IOException {
  Header contentEncodingHeader=method.getResponseHeader("Content-Encoding");
  if (contentEncodingHeader != null) {
    String contentEncoding=contentEncodingHeader.getValue();
    if (contentEncoding.contains("gzip")) {
      respBody=new GZIPInputStream(respBody);
    }
 else     if (contentEncoding.contains("deflate")) {
      respBody=new InflaterInputStream(respBody);
    }
  }
 else {
    Header contentTypeHeader=method.getResponseHeader("Content-Type");
    if (contentTypeHeader != null) {
      String contentType=contentTypeHeader.getValue();
      if (contentType != null) {
        if (contentType.startsWith("application/x-gzip-compressed")) {
          respBody=new GZIPInputStream(respBody);
        }
 else         if (contentType.startsWith("application/x-deflate")) {
          respBody=new InflaterInputStream(respBody);
        }
      }
    }
  }
  return respBody;
}
 

Example 101

From project sparqled, under directory /recommendation-servlet/src/test/java/org/sindice/analytics/servlet/.

Source file: TestAssistedSparqlEditorSevlet.java

  30 
vote

@Before public void setUp() throws Exception {
  RDFParserRegistry.getInstance().add(new RDFParserFactory(){
    @Override public RDFFormat getRDFFormat(){
      return SesameNxParser.nquadsFormat;
    }
    @Override public RDFParser getParser(){
      return new SesameNxParser();
    }
  }
);
  client=new HttpClient();
  aseTester=new ServletTester();
  aseTester.setContextPath("/");
  aseTester.setAttribute(MemorySesameServletHelper.FILE_STREAM,new GZIPInputStream(new FileInputStream(dgsInput)));
  aseTester.setAttribute(MemorySesameServletHelper.FORMAT,SesameNxParser.nquadsFormat);
  aseTester.addServlet(MemorySesameServletHelper.class,"/DGS-repo");
  String url=aseTester.createSocketConnector(true);
  final String dgsRepoServletUrl=url + "/DGS-repo";
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.BACKEND,BackendType.HTTP.toString());
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.BACKEND_ARGS,new String[]{dgsRepoServletUrl});
  aseTester.addServlet(AssistedSparqlEditorServlet.class,"/SparqlEditorServlet");
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.RANKING_CONFIGURATION,"src/main/resources/default-ranking.yaml");
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.DOMAIN_URI_PREFIX,DataGraphSummaryVocab.DOMAIN_URI_PREFIX);
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.PAGINATION,1000);
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.DATASET_LABEL_DEF,DatasetLabel.SECOND_LEVEL_DOMAIN.toString());
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.CLASS_ATTRIBUTES,new String[]{AnalyticsClassAttributes.DEFAULT_CLASS_ATTRIBUTE});
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.GRAPH_SUMMARY_GRAPH,DataGraphSummaryVocab.GRAPH_SUMMARY_GRAPH.toString());
  aseTester.setAttribute(AssistedSparqlEditorListener.RECOMMENDER_WRAPPER + AssistedSparqlEditorListener.LIMIT,limit);
  aseBaseUrl=url + "/SparqlEditorServlet";
  System.out.println("dgsRepoURL: [" + dgsRepoServletUrl + "]");
  System.out.println("aseURL: [" + aseBaseUrl + "]");
  aseTester.start();
}
 

Example 102

From project Airports, under directory /src/com/nadmm/airports/.

Source file: DownloadActivity.java

  29 
vote

protected int downloadData(final DataInfo data){
  mHandler.post(new Runnable(){
    @Override public void run(){
      mTracker.initProgress(R.string.installing,data.size);
    }
  }
);
  try {
    DefaultHttpClient httpClient=new DefaultHttpClient();
    if (!DatabaseManager.DATABASE_DIR.exists() && !DatabaseManager.DATABASE_DIR.mkdirs()) {
      UiUtils.showToast(mActivity,"Unable to create folder on external storage");
      return -3;
    }
    File dbFile=new File(DatabaseManager.DATABASE_DIR,data.fileName);
    ResultReceiver receiver=new ResultReceiver(mHandler){
      protected void onReceiveResult(      int resultCode,      Bundle resultData){
        long progress=resultData.getLong(NetworkUtils.CONTENT_PROGRESS);
        publishProgress((int)progress);
      }
    }
;
    Bundle result=new Bundle();
    NetworkUtils.doHttpGet(mActivity,httpClient,HOST,PORT,PATH + "/" + data.fileName+ ".gz","uuid=" + UUID.randomUUID().toString(),dbFile,receiver,result,GZIPInputStream.class);
  }
 catch (  Exception e) {
    UiUtils.showToast(mActivity,e.getMessage());
    return -1;
  }
  return 0;
}
 

Example 103

From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/http/.

Source file: RequestHandler.java

  29 
vote

private String getStringFromGzipStream(GZIPInputStream in){
  BufferedInputStream buff_in=new BufferedInputStream(in);
  int byte_read=0;
  int buff_size=512;
  byte[] byte_buffer=new byte[buff_size];
  ByteArrayBuffer buff_array=new ByteArrayBuffer(50);
  try {
    while (true) {
      byte_read=buff_in.read(byte_buffer);
      if (byte_read == -1) {
        break;
      }
      buff_array.append(byte_buffer,0,byte_read);
    }
    return new String(buff_array.toByteArray());
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    return null;
  }
}
 

Example 104

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

Source file: JavaObjectSerializer.java

  29 
vote

@Override public <T>T deserialize(byte[] bytes,Class<T> type,boolean decompress) throws IOException {
  if (Map.class.isAssignableFrom(type))   return (T)deserializeMap(bytes,decompress);
  if (List.class.isAssignableFrom(type)) {
    return (T)deserializeList(bytes,decompress);
  }
  ObjectInputStream in=null;
  try {
    ByteArrayInputStream byteStream=new ByteArrayInputStream(bytes);
    in=new ObjectInputStream(decompress ? new GZIPInputStream(byteStream) : byteStream){
      @Override protected Class<?> resolveClass(      ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        try {
          return Class.forName(desc.getName(),false,Thread.currentThread().getContextClassLoader());
        }
 catch (        ClassNotFoundException exception) {
          return super.resolveClass(desc);
        }
      }
    }
;
    return (T)in.readObject();
  }
 catch (  ClassNotFoundException exception) {
    throw new FlowException("unable to deserialize data",exception);
  }
 finally {
    if (in != null)     in.close();
  }
}
 

Example 105

From project eclipsefp, under directory /net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/wizards/.

Source file: Extractor.java

  29 
vote

private static void extract(final InputStream stream,final IProject dest) throws IOException, CoreException {
  TarInputStream tis=new TarInputStream(new GZIPInputStream(stream));
  TarEntry entry=tis.getNextEntry();
  while (entry != null) {
    if (!entry.isDirectory()) {
      IPath entryPath=new Path(entry.getName());
      if (entryPath.segmentCount() > 0) {
        entryPath=entryPath.removeFirstSegments(1);
      }
      write(entryPath,dest,readPartially(tis));
    }
    entry=tis.getNextEntry();
  }
  tis.close();
}
 

Example 106

From project freemind, under directory /plugins/wsl/src/onekin/WSL/config/.

Source file: WSL_MediaWikiConfig.java

  29 
vote

/** 
 * This methods uncompresses tar.gz files
 * @param mediaWikiFileName Uncompress tar.gz
 */
private void uncompressMW(String mediaWikiFileName,File dest){
  try {
    dest.mkdir();
    TarInputStream tin=new TarInputStream(new GZIPInputStream(new FileInputStream(new File(mediaWikiFileName))));
    TarEntry tarEntry=tin.getNextEntry();
    while (tarEntry != null) {
      File destPath=new File(dest.toString() + File.separatorChar + tarEntry.getName());
      if (tarEntry.isDirectory()) {
        destPath.mkdir();
      }
 else {
        FileOutputStream fout=new FileOutputStream(destPath);
        tin.copyEntryContents(fout);
        fout.close();
      }
      tarEntry=tin.getNextEntry();
    }
    tin.close();
    File oldMWDir=new File(installationDir.getText() + File.separatorChar + mediaWikiFileName.substring(0,mediaWikiFileName.length() - 7));
    oldMWDir.renameTo(new File(installationDir.getText() + File.separatorChar + wikiName.getText()));
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 107

From project genobyte, under directory /genobyte/src/main/java/org/obiba/bitwise/client/.

Source file: SeparatedValuesParser.java

  29 
vote

private InputStream getInputStream(File f) throws IOException {
  InputStream is=new FileInputStream(f);
  byte magicBytes[]=new byte[4];
  is.read(magicBytes,0,2);
  is.close();
  ByteBuffer bb=ByteBuffer.wrap(magicBytes);
  bb.order(ByteOrder.LITTLE_ENDIAN);
  int magicNumber=bb.getInt();
  if (magicNumber == GZIPInputStream.GZIP_MAGIC) {
    return new LargeGZIPInputStream(new FileInputStream(f));
  }
  return new FileInputStream(f);
}
 

Example 108

From project github-java-sdk, under directory /core/src/main/java/com/github/api/v2/services/impl/.

Source file: GitHubApiGateway.java

  29 
vote

/** 
 * Gets the wrapped input stream.
 * @param is the is
 * @param gzip the gzip
 * @return the wrapped input stream
 * @throws IOException Signals that an I/O exception has occurred.
 */
protected InputStream getWrappedInputStream(InputStream is,boolean gzip) throws IOException {
  if (gzip) {
    return new BufferedInputStream(new GZIPInputStream(is));
  }
 else {
    return new BufferedInputStream(is);
  }
}
 

Example 109

From project hudson-test-harness, under directory /src/test/java/hudson/model/.

Source file: UsageStatisticsTest.java

  29 
vote

/** 
 * Makes sure that the stat data can be decrypted safely.
 */
public void testRoundtrip() throws Exception {
  String privateKey="30820276020100300d06092a864886f70d0101010500048202603082025c0201000281810084cababdb38040f659c2cb07a36d758f46e84ebc3d6ba39d967aedf1d396b0788ed3ab868d45ce280b1102b434c2a250ddc3254defe1785ab4f94d7038cf69ecca16753d2de3f6ad8976b3f74902d8634111d730982da74e1a6e3fc0bc3523bba53e45b8a8cbfd0321b94efc9f7fefbe66ad85281e3d0323d87f4426ec51204f0203010001028180784deaacdea8bd31f2d44578601954be3f714b93c2d977dbd76efb8f71303e249ad12dbeb2d2a1192a1d7923a6010768d7e06a3597b3df83de1d5688eb0f0e58c76070eddd696682730c93890dc727564c65dc8416bfbde5aad4eb7a97ed923efb55a291daf3c00810c0e43851298472fd539aab355af8cedcf1e9a0cbead661024100c498375102b068806c71dec838dc8dfa5624fb8a524a49cffadc19d10689a8c9c26db514faba6f96e50a605122abd3c9af16e82f2b7565f384528c9f31ea5947024100aceafd31d7f4872a873c7e5fe88f20c2fb086a053c6970026b3ce364768e2033100efb1ad8f2010fe53454a29decedc23a8a0c8df347742b1f13e11bd3a284b9024100931321470cd0f6cd24d4278bf8e61f9d69b6ef2bf3163a944aa340f91c7ffdf33aeea22b18cc43514af6714a21bb148d6cdca14530a8fa65acd7a8f62bfc9b5f024067452059f8438dc61466488336fce3f00ec483ad04db638dce45daf850e5a8cd5635dc39b87f2fab32940247ec5167ddabe06e870858104500967ac687aa73e102407e3b7997503e18d8d0f094d5e0bd5d57cb93cb39a2fc42cec1ea9a1562786438b61139e45813204d72c919f5397e139ad051d98e4d0f8a06d237f42c0d8440fb";
  String publicKey="30819f300d06092a864886f70d010101050003818d003081890281810084cababdb38040f659c2cb07a36d758f46e84ebc3d6ba39d967aedf1d396b0788ed3ab868d45ce280b1102b434c2a250ddc3254defe1785ab4f94d7038cf69ecca16753d2de3f6ad8976b3f74902d8634111d730982da74e1a6e3fc0bc3523bba53e45b8a8cbfd0321b94efc9f7fefbe66ad85281e3d0323d87f4426ec51204f0203010001";
  String data=new UsageStatistics(publicKey).getStatData();
  System.out.println(data);
  KeyFactory keyFactory=KeyFactory.getInstance("RSA");
  PrivateKey priv=keyFactory.generatePrivate(new PKCS8EncodedKeySpec(Util.fromHexString(privateKey)));
  Cipher cipher=Cipher.getInstance("RSA");
  cipher.init(Cipher.DECRYPT_MODE,priv);
  byte[] cipherText=Base64.decode(data.toCharArray());
  InputStreamReader r=new InputStreamReader(new GZIPInputStream(new CombinedCipherInputStream(new ByteArrayInputStream(cipherText),cipher,"AES",1024)),"UTF-8");
  JSONObject o=JSONObject.fromObject(IOUtils.toString(r));
  System.out.println(o);
  assertEquals(1,o.getInt("stat"));
}
 

Example 110

From project imdb, under directory /src/main/java/org/neo4j/examples/imdb/parser/.

Source file: ImdbParser.java

  29 
vote

/** 
 * Get file reader that corresponds to file extension.
 * @param file the file name
 * @param pattern TODO
 * @param skipLines TODO
 * @return a file reader that uncompresses data if needed
 * @throws IOException
 * @throws FileNotFoundException
 */
private BufferedReader getFileReader(final String file,String pattern,int skipLines) throws IOException, FileNotFoundException {
  BufferedReader fileReader;
  if (file.endsWith(".gz")) {
    fileReader=new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
  }
 else   if (file.endsWith(".zip")) {
    fileReader=new BufferedReader(new InputStreamReader(new ZipInputStream(new FileInputStream(file))));
  }
 else {
    fileReader=new BufferedReader(new FileReader(file));
  }
  String line="";
  while (!pattern.equals(line)) {
    line=fileReader.readLine();
  }
  for (int i=0; i < skipLines; i++) {
    line=fileReader.readLine();
  }
  return fileReader;
}
 

Example 111

From project jdeb, under directory /src/test/java/org/vafer/jdeb/ant/.

Source file: DebAntTaskTestCase.java

  29 
vote

public void testTarFileSet() throws Exception {
  project.executeTarget("tarfileset");
  File deb=new File("target/test-classes/test.deb");
  assertTrue("package not build",deb.exists());
  ArArchiveInputStream in=new ArArchiveInputStream(new FileInputStream(deb));
  ArArchiveEntry entry;
  while ((entry=in.getNextArEntry()) != null) {
    if (entry.getName().equals("data.tar.gz")) {
      TarInputStream tar=new TarInputStream(new GZIPInputStream(new NonClosingInputStream(in)));
      TarEntry tarentry;
      while ((tarentry=tar.getNextEntry()) != null) {
        assertTrue("prefix",tarentry.getName().startsWith("./foo/"));
        if (tarentry.isDirectory()) {
          assertEquals("directory mode (" + tarentry.getName() + ")",040700,tarentry.getMode());
        }
 else {
          assertEquals("file mode (" + tarentry.getName() + ")",0100600,tarentry.getMode());
        }
        assertEquals("user","ebourg",tarentry.getUserName());
        assertEquals("group","ebourg",tarentry.getGroupName());
      }
      tar.close();
    }
 else {
      long skip=entry.getLength();
      while (skip > 0) {
        long skipped=in.skip(skip);
        if (skipped == -1) {
          throw new IOException("Failed to skip");
        }
        skip-=skipped;
      }
    }
  }
  in.close();
}
 

Example 112

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

Source file: DataStreamFactory.java

  29 
vote

public static DataInputStream createDataInputStream(InputStream in,boolean buffered,boolean gzip_outside,boolean compression,int buffer_size){
  try {
    if (!buffered) {
      return new DataInputStream(compression ? new GZIPInputStream(in) : in);
    }
 else {
      if (gzip_outside) {
        return new DataInputStream(compression ? new GZIPInputStream(new BufferedInputStream(in,buffer_size)) : new BufferedInputStream(in,buffer_size));
      }
 else {
        return new DataInputStream(compression ? new BufferedInputStream(new GZIPInputStream(in,buffer_size)) : new BufferedInputStream(in,buffer_size));
      }
    }
  }
 catch (  IOException e) {
    throw new AtlasException(e);
  }
}
 

Example 113

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

Source file: DictionarySerializer.java

  29 
vote

/** 
 * Creates  {@link Entry}s form the given  {@link InputStream} andforwards these  {@link Entry}s to the  {@link EntryInserter}.
 * @param in
 * @param inserter
 * @throws IOException
 * @throws InvalidFormatException 
 */
public static void create(InputStream in,EntryInserter inserter) throws IOException, InvalidFormatException {
  DictionaryContenthandler profileContentHandler=new DictionaryContenthandler(inserter);
  XMLReader xmlReader;
  try {
    xmlReader=XMLReaderFactory.createXMLReader();
    xmlReader.setContentHandler(profileContentHandler);
    xmlReader.parse(new InputSource(new GZIPInputStream(in)));
  }
 catch (  SAXException e) {
    throw new InvalidFormatException("The profile data stream has" + "an invalid format!",e);
  }
}
 

Example 114

From project liquidfeedback-java-sdk, under directory /core/src/main/java/lfapi/v2/services/impl/.

Source file: LiquidFeedbackApiGateway.java

  29 
vote

/** 
 * Gets the wrapped input stream.
 * @param is the is
 * @param gzip the gzip
 * @return the wrapped input stream
 * @throws IOException Signals that an I/O exception has occurred.
 */
protected static InputStream getWrappedInputStream(InputStream is,boolean gzip) throws IOException {
  if (gzip) {
    return new BufferedInputStream(new GZIPInputStream(is));
  }
 else {
    return new BufferedInputStream(is);
  }
}
 

Example 115

From project logback, under directory /logback-core/src/test/java/ch/qos/logback/core/util/.

Source file: Compare.java

  29 
vote

public static boolean gzCompare(String file1,String file2) throws FileNotFoundException, IOException {
  BufferedReader in1=new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file1))));
  BufferedReader in2=new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file2))));
  String s1;
  int lineCounter=0;
  while ((s1=in1.readLine()) != null) {
    lineCounter++;
    String s2=in2.readLine();
    if (!s1.equals(s2)) {
      System.out.println("Files [" + file1 + "] and ["+ file2+ "] differ on line "+ lineCounter);
      System.out.println("One reads:  [" + s1 + "].");
      System.out.println("Other reads:[" + s2 + "].");
      outputFile(file1);
      outputFile(file2);
      return false;
    }
  }
  if (in2.read() != -1) {
    System.out.println("File [" + file2 + "] longer than file ["+ file1+ "].");
    outputFile(file1);
    outputFile(file2);
    return false;
  }
  return true;
}
 

Example 116

From project medsavant, under directory /MedSavantServerEngine/src/org/ut/biolab/medsavant/db/variants/.

Source file: VCFIterator.java

  29 
vote

private void createReader() throws IOException {
  LOG.info(String.format("Parsing file %s",files[fileIndex].getName()));
  Reader reader;
  if (files[fileIndex].getAbsolutePath().endsWith(".gz") || files[fileIndex].getAbsolutePath().endsWith(".zip")) {
    FileInputStream fin=new FileInputStream(files[fileIndex].getAbsolutePath());
    reader=new InputStreamReader(new GZIPInputStream(fin));
  }
 else {
    reader=new FileReader(files[fileIndex]);
  }
  r=new CSVReader(reader,'\t');
  header=VCFParser.parseVCFHeader(r);
  variantIdOffset=0;
}
 

Example 117

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

Source file: CompressedStreamTools.java

  29 
vote

public static NBTTagCompound loadGzippedCompoundFromOutputStream(InputStream input) throws IOException {
  DataInputStream datainputstream=new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)));
  try {
    NBTTagCompound nbttagcompound=read(datainputstream);
    return nbttagcompound;
  }
  finally {
    datainputstream.close();
  }
}
 

Example 118

From project onebusaway-android, under directory /src/com/joulespersecond/oba/.

Source file: ObaDefaultConnection.java

  29 
vote

private Reader get_Froyo() throws IOException {
  boolean useGzip=false;
  mConnection.setRequestProperty("Accept-Encoding","gzip");
  InputStream in=mConnection.getInputStream();
  final Map<String,List<String>> headers=mConnection.getHeaderFields();
  final Set<Map.Entry<String,List<String>>> set=headers.entrySet();
  for (Iterator<Map.Entry<String,List<String>>> i=set.iterator(); i.hasNext(); ) {
    Map.Entry<String,List<String>> entry=i.next();
    if ("Content-Encoding".equalsIgnoreCase(entry.getKey())) {
      for (Iterator<String> j=entry.getValue().iterator(); j.hasNext(); ) {
        String str=j.next();
        if (str.equalsIgnoreCase("gzip")) {
          useGzip=true;
          break;
        }
      }
      if (useGzip) {
        break;
      }
    }
  }
  if (useGzip) {
    return new InputStreamReader(new BufferedInputStream(new GZIPInputStream(in),8 * 1024));
  }
 else {
    return new InputStreamReader(new BufferedInputStream(in,8 * 1024));
  }
}
 

Example 119

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

Source file: Inputs.java

  29 
vote

/** 
 * Read lines from a textfile with the given encoding. If the filename ends with .gz, then the data is automatically unzipped when read.
 * @param source   textfile with lines separated by \n character
 * @param encoding encoding of file, e.g. "UTF-8"
 * @return Input that provides lines from the textfiles as strings
 */
public static Input<String,IOException> text(final File source,final String encoding){
  return new Input<String,IOException>(){
    @Override public <ReceiverThrowableType extends Throwable>void transferTo(    Output<? super String,ReceiverThrowableType> output) throws IOException, ReceiverThrowableType {
      InputStream stream=new FileInputStream(source);
      if (source.getName().endsWith(".gz")) {
        stream=new GZIPInputStream(stream);
      }
      final BufferedReader reader=new BufferedReader(new InputStreamReader(stream,encoding));
      try {
        output.receiveFrom(new Sender<String,IOException>(){
          @Override public <ReceiverThrowableType extends Throwable>void sendTo(          Receiver<? super String,ReceiverThrowableType> receiver) throws ReceiverThrowableType, IOException {
            String line;
            while ((line=reader.readLine()) != null) {
              receiver.receive(line);
            }
          }
        }
);
      }
  finally {
        reader.close();
      }
    }
  }
;
}