java.util.zip.GZIPInputStream#close ( )源码实例Demo

下面列出了java.util.zip.GZIPInputStream#close ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Load wordVectors from a gzipped csv file
 */
private void loadGZipped() {
  try {
    GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(wordVectorLocation));
    File tmpFile =
        Paths.get(System.getProperty("java.io.tmpdir"), "wordmodel-tmp.csv").toFile();
    tmpFile.delete();
    FileOutputStream fos = new FileOutputStream(tmpFile);
    int length;
    byte[] buffer = new byte[1024];
    while ((length = gzis.read(buffer)) > 0) {
      fos.write(buffer, 0, length);
    }
    fos.close();
    gzis.close();

    // Try loading decompressed CSV file
    boolean success = loadEmbeddingFromCSV(tmpFile);
    if (!success) {
      throw new RuntimeException("Could not load the word vector file.");
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
源代码2 项目: Ak47   文件: CompressUtil.java
/**
 * GZIP decompression
 * 
 * GZIP解压
 * 
 * @param compressed                    sources bytes to be decompressed
 * @return                              decompressed bytes
 * @throws IOException                  i/o wrong
 */
public static byte[] decompressGzip(byte[] compressed) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gis = new GZIPInputStream(bis);
    try {
        byte[] buffer = new byte[READ_BUFFER_SIZE];
        int read = 0;
        while ((read = gis.read(buffer)) != -1) {
            bos.write(buffer, 0, read);
        }
    } finally {
        gis.close();
    }

    return bos.toByteArray();
}
 
源代码3 项目: vxquery   文件: SimpleXQueryTest.java
private static String gunzip(String dir, String filename) {
    try {
        GZIPInputStream in = new GZIPInputStream(
                new BufferedInputStream(new FileInputStream(new File(dir + filename + ".gz"))));
        File temp = File.createTempFile("vxquery", filename);
        temp.deleteOnExit();
        FileOutputStream out = new FileOutputStream(temp);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
        return temp.getCanonicalPath();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
源代码4 项目: Cynthia   文件: CommonUtil.java
public static String gzip2str(byte[] byteArray, String code)
		throws Exception {
	GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(
			byteArray));
	ByteArrayOutputStream baos = new ByteArrayOutputStream();

	byte[] buf = new byte[1024];

	while (true) {
		int len = gzis.read(buf);
		if (len == -1) {
			break;
		}

		baos.write(buf, 0, len);
	}

	gzis.close();
	baos.close();

	return baos.toString(code);
}
 
源代码5 项目: freehealth-connector   文件: IOUtils.java
/**
 * Decompress.
 * 
 * @param unSealmessage
 *            the un sealmessage
 * @return the byte[]
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static byte[] decompress(byte[] unSealmessage) throws IOException {
	long size = unSealmessage.length;
	ByteArrayInputStream inputstream = new ByteArrayInputStream(unSealmessage);
	GZIPInputStream input = new GZIPInputStream(inputstream);
	int i;
	ByteArrayOutputStream o = new ByteArrayOutputStream();

	byte buffer[] = new byte[1024];
	while ((i = input.read(buffer)) > 0) {
		o.write(buffer, 0, i);
	}
	o.flush();
	input.close();
	inputstream.close();
	o.close();
	byte[] ret = o.toByteArray();
	LOG.debug("Decompression of data from " + size + " bytes to " + ret.length + " bytes");
	return ret;
}
 
源代码6 项目: dsworkbench   文件: WorldDecorationHolder.java
private static void loadWorld() throws Exception {
  try {
    GZIPInputStream fin = new GZIPInputStream(new FileInputStream("world.dat.gz"));
    ByteBuffer bb = ByteBuffer.allocate(1000000);
    byte[] d = new byte[1024];
    int c = 0;
    while ((c = fin.read(d)) != -1) {
      bb.put(d, 0, c);
    }
    decoration = bb.array();
    fin.close();
  } catch (Exception e) {
    logger.error("Failed to read decoration file");
    throw new Exception("Unable to read decoration file", e);
  }
  loadTextures();
}
 
源代码7 项目: freehealth-connector   文件: IOUtils.java
/**
 * Decompress.
 * 
 * @param unSealmessage
 *            the un sealmessage
 * @return the byte[]
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static byte[] decompress(byte[] unSealmessage) throws IOException {
	long size = unSealmessage.length;
	ByteArrayInputStream inputstream = new ByteArrayInputStream(unSealmessage);
	GZIPInputStream input = new GZIPInputStream(inputstream);
	int i;
	ByteArrayOutputStream o = new ByteArrayOutputStream();

	byte buffer[] = new byte[1024];
	while ((i = input.read(buffer)) > 0) {
		o.write(buffer, 0, i);
	}
	o.flush();
	input.close();
	inputstream.close();
	o.close();
	byte[] ret = o.toByteArray();
	LOG.debug("Decompression of data from " + size + " bytes to " + ret.length + " bytes");
	return ret;
}
 
源代码8 项目: xDrip-plus   文件: JoH.java
public static byte[] decompressBytesToBytes(byte[] bytes) {
    try {
        Log.d(TAG, "Decompressing  bytes size: " + bytes.length);
        byte[] buffer = new byte[8192];
        int bytes_read;
        ByteArrayInputStream input = new ByteArrayInputStream(bytes);
        ByteArrayOutputStream output = new ByteArrayOutputStream(bytes.length);
        GZIPInputStream gzipped_data = new GZIPInputStream(input, buffer.length);
        while ((bytes_read = gzipped_data.read(buffer)) != -1) {
            output.write(buffer, 0, bytes_read);
        }
        gzipped_data.close();
        input.close();
        // output.close();
        return output.toByteArray();
    } catch (Exception e) {
        Log.e(TAG, "Exception in decompress: " + e.toString());
        return new byte[0];
    }
}
 
源代码9 项目: panama   文件: GzipUtils.java
/**
 *  gzip解密
 * @param data
 * @return
 * @throws Exception
 * byte[]
 */
public static byte[] ungzip(byte[] data) throws Exception {  
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    GZIPInputStream gzip = new GZIPInputStream(bis);
    byte[] buf = new byte[1024];  
    int num = -1;  
    ByteArrayOutputStream bos = new ByteArrayOutputStream();  
    while ((num = gzip.read(buf, 0, buf.length)) != -1) {  
        bos.write(buf, 0, num);  
    }  
    gzip.close();  
    bis.close();  
    byte[] ret = bos.toByteArray();  
    bos.flush();  
    bos.close();  
    return ret;  
}
 
private static String uncompressString(ByteBuffer input) throws IOException {
    byte[] bytes = input.array();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPInputStream is = new GZIPInputStream(bais);

    int chunkSize = 1024;
    byte[] buffer = new byte[chunkSize];
    int length = 0;
    while ((length = is.read(buffer, 0, chunkSize)) != -1) {
        baos.write(buffer, 0, length);
    }

    String result = new String(baos.toByteArray(), "UTF-8");

    is.close();
    baos.close();
    bais.close();

    return result;
}
 
源代码11 项目: jstorm   文件: Utils.java
public static byte[] gunzip(byte[] data) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        GZIPInputStream in = new GZIPInputStream(bis);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) >= 0) {
            bos.write(buffer, 0, len);
        }
        in.close();
        bos.close();
        return bos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
源代码12 项目: pdfxtk   文件: Trans.java
public static byte[] unzip(byte[] zipped) 
  throws IOException {
    GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(zipped));
    byte[] len          = new byte[4];
    zin.read(len);
    byte[] result = new byte[byte2int(len)];      
    zin.read(result);
    zin.close();
    return result;
}
 
源代码13 项目: mt-flume   文件: TestHDFSCompressedDataStream.java
@Test
public void testGzipDurabilityWithSerializer() throws Exception {
  Context context = new Context();
  context.put("serializer", "AVRO_EVENT");

  HDFSCompressedDataStream writer = new HDFSCompressedDataStream();
  writer.configure(context);

  writer.open(fileURI, factory.getCodec(new Path(fileURI)),
      SequenceFile.CompressionType.BLOCK);

  String[] bodies = { "yarf!", "yarfing!" };
  writeBodies(writer, bodies);

  int found = 0;
  int expected = bodies.length;
  List<String> expectedBodies = Lists.newArrayList(bodies);

  GZIPInputStream cmpIn = new GZIPInputStream(new FileInputStream(file));
  DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
  DataFileStream<GenericRecord> avroStream =
      new DataFileStream<GenericRecord>(cmpIn, reader);
  GenericRecord record = new GenericData.Record(avroStream.getSchema());
  while (avroStream.hasNext()) {
    avroStream.next(record);
    CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
    String bodyStr = decoder.decode((ByteBuffer) record.get("body"))
        .toString();
    expectedBodies.remove(bodyStr);
    found++;
  }
  avroStream.close();
  cmpIn.close();

  Assert.assertTrue("Found = " + found + ", Expected = " + expected
      + ", Left = " + expectedBodies.size() + " " + expectedBodies,
      expectedBodies.size() == 0);
}
 
源代码14 项目: DoraemonKit   文件: GunzippingOutputStream.java
@Override
public Void call() throws IOException {
  GZIPInputStream in = new GZIPInputStream(mIn);
  try {
    StreamUtil.copy(in, mOut, new byte[1024]);
  } finally {
    in.close();
    mOut.close();
  }
  return null;
}
 
源代码15 项目: util4j   文件: GZipUtils.java
/**
 * 数据解压缩
 * @param is
 * @param os
 * @throws Exception
 */
public static void decompress(InputStream is, OutputStream os) throws Exception {
	GZIPInputStream gis = new GZIPInputStream(is);
	try {
		int count;
		byte data[] = new byte[BUFFER];
		while ((count = gis.read(data, 0, BUFFER)) != -1) {
			os.write(data, 0, count);
		}
	}finally {
		gis.close();
	}
}
 
源代码16 项目: Xndroid   文件: GZipUtils.java
/**
 * 数据解压缩
 *
 * @param is
 * @param os
 * @throws Exception
 */
public static void decompress(InputStream is, OutputStream os)
        throws Exception {

    GZIPInputStream gis = new GZIPInputStream(is);

    int count;
    byte data[] = new byte[BUFFER];
    while ((count = gis.read(data, 0, BUFFER)) != -1) {
        os.write(data, 0, count);
    }

    gis.close();
}
 
源代码17 项目: cxf   文件: JAXRSClientServerBookTest.java
@Test
public void testGetBookQueryGZIP() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/";
    WebClient wc = WebClient.create(address);
    wc.acceptEncoding("gzip,deflate");
    wc.encoding("gzip");
    InputStream r = wc.get(InputStream.class);
    assertNotNull(r);
    GZIPInputStream in = new GZIPInputStream(r);
    String s = IOUtils.toString(in);
    in.close();
    assertTrue(s, s.contains("id>124"));
}
 
源代码18 项目: AffectiveTweets   文件: SWN3LexiconEvaluator.java
@Override
public void processDict() throws IOException {


	FileInputStream fin = new FileInputStream(this.path);
	GZIPInputStream gzis = new GZIPInputStream(fin);
	InputStreamReader xover = new InputStreamReader(gzis);
	BufferedReader bf = new BufferedReader(xover);


	String line = "";

	// discard comments
	while ((line = bf.readLine()) != null) {
		if (line.startsWith("#") || line.startsWith("				#")) {
			continue;
		}

		String[] data = line.split("\t");

		// Difference between positive and negative score for one particular Synset
		Double polScore = Double.parseDouble(data[2])
				- Double.parseDouble(data[3]);

		// extract all the synset terms
		String[] sysSetTerms = data[4].split(" ");
		for (String w : sysSetTerms) {
			String[] w_n = w.split("#");

			String word=w_n[0];
			// the word's rank, small values indicate a more popular meaning
			// More popular word receive a higher weight
			int rank = Integer.parseInt(w_n[1]);

			if (this.dict.containsKey(word)) {
				Double prevScore=this.dict.get(word);
				this.dict.put(word, prevScore + polScore/(1+rank));
			} else {
				this.dict.put(word, polScore/(1+rank));
			}
		}
	}

	bf.close();
	xover.close();
	gzis.close();
	fin.close();
}
 
源代码19 项目: BurpSuite-Team-Extension   文件: CustomURLServer.java
private String decompress(byte[] compressed) throws IOException {
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
        GZIPInputStream gis = new GZIPInputStream(bis);
        BufferedReader br = new BufferedReader(new InputStreamReader(gis, StandardCharsets.UTF_8));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
            sb.append("\n");
        }
        br.close();
        gis.close();
        bis.close();
        String strippedJson = sb.toString();

        this.sharedValues.getCallbacks().printOutput(
                "StrippedJson: " + strippedJson);
        String[] strippedJsonByDelimiter =
                strippedJson.split(new String(new byte[]{127}));
        for (String jsonPiece : strippedJsonByDelimiter) {
            this.sharedValues.getCallbacks().printOutput("Piece: "+ jsonPiece);
        }
        JsonObject httpService = new JsonObject();
        httpService.addProperty("host",strippedJsonByDelimiter[2].trim());
        httpService.addProperty("port",strippedJsonByDelimiter[3].trim());
        httpService.addProperty("protocol",strippedJsonByDelimiter[4].trim());
        JsonObject mainJson = new JsonObject();
        mainJson.add("request",
                this.sharedValues.getGson().newBuilder().create().toJsonTree(fromBytesToString(strippedJsonByDelimiter[0].getBytes())));
        mainJson.add("response",
                this.sharedValues.getGson().newBuilder().create().toJsonTree(fromBytesToString(strippedJsonByDelimiter[1].getBytes())));
        mainJson.add("httpService",httpService);

        return mainJson.toString();

    } catch (NumberFormatException e){
        sharedValues.getCallbacks().printError("Decompress: " +
                e.getMessage());
        return "";
    }

}
 
源代码20 项目: hbase   文件: TestGzipFilter.java
@Test
public void testGzipFilter() throws Exception {
  String path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1;

  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  GZIPOutputStream os = new GZIPOutputStream(bos);
  os.write(VALUE_1);
  os.close();
  byte[] value_1_gzip = bos.toByteArray();

  // input side filter

  Header[] headers = new Header[2];
  headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_BINARY);
  headers[1] = new BasicHeader("Content-Encoding", "gzip");
  Response response = client.put(path, headers, value_1_gzip);
  assertEquals(200, response.getCode());

  Table table = TEST_UTIL.getConnection().getTable(TABLE);
  Get get = new Get(Bytes.toBytes(ROW_1));
  get.addColumn(Bytes.toBytes(CFA), Bytes.toBytes("1"));
  Result result = table.get(get);
  byte[] value = result.getValue(Bytes.toBytes(CFA), Bytes.toBytes("1"));
  assertNotNull(value);
  assertTrue(Bytes.equals(value, VALUE_1));

  // output side filter

  headers[0] = new BasicHeader("Accept", Constants.MIMETYPE_BINARY);
  headers[1] = new BasicHeader("Accept-Encoding", "gzip");
  response = client.get(path, headers);
  assertEquals(200, response.getCode());
  ByteArrayInputStream bis = new ByteArrayInputStream(response.getBody());
  GZIPInputStream is = new GZIPInputStream(bis);
  value = new byte[VALUE_1.length];
  is.read(value, 0, VALUE_1.length);
  assertTrue(Bytes.equals(value, VALUE_1));
  is.close();
  table.close();

  testScannerResultCodes();
}