當前位置: 首頁>>代碼示例>>Java>>正文


Java GZIPOutputStream類代碼示例

本文整理匯總了Java中java.util.zip.GZIPOutputStream的典型用法代碼示例。如果您正苦於以下問題:Java GZIPOutputStream類的具體用法?Java GZIPOutputStream怎麽用?Java GZIPOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GZIPOutputStream類屬於java.util.zip包,在下文中一共展示了GZIPOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encode

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, MessageOrBuilder in, List<Object> out)
        throws Exception {
    Message msg = in instanceof Message ? (Message) in : ((Message.Builder) in).build();

    int typeId = register.getTypeId(msg.getClass());
    if (typeId == Integer.MIN_VALUE) {
        throw new IllegalArgumentException("Unrecognisable message type, maybe not registered! ");
    }
    byte[] messageData = msg.toByteArray();

    if (messageData.length <= 0) {
        out.add(ByteBufAllocator.DEFAULT.heapBuffer().writeInt(typeId)
                .writeInt(0));
        return;
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream def = new GZIPOutputStream(bos);
    def.write(messageData);
    def.flush();
    def.close();
    byte[] compressedData = bos.toByteArray();
    out.add(ByteBufAllocator.DEFAULT.heapBuffer().writeInt(typeId).writeInt(compressedData.length)
            .writeBytes(compressedData));
}
 
開發者ID:CloudLandGame,項目名稱:CloudLand-Server,代碼行數:27,代碼來源:IdBasedProtobufEncoder.java

示例2: write

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Write a tile image to a stream.
 *
 * @param tile the image
 * @param out the stream
 *
 * @throws ImageIOException if the write fails
 */
public static void write(BufferedImage tile, OutputStream out)
                                                         throws IOException {
  ByteBuffer bb;

  // write the header
  bb = ByteBuffer.allocate(18);

  bb.put("VASSAL".getBytes())
    .putInt(tile.getWidth())
    .putInt(tile.getHeight())
    .putInt(tile.getType());

  out.write(bb.array());

  // write the tile data
  final DataBufferInt db = (DataBufferInt) tile.getRaster().getDataBuffer();
  final int[] data = db.getData();

  bb = ByteBuffer.allocate(4*data.length);
  bb.asIntBuffer().put(data);

  final GZIPOutputStream zout = new GZIPOutputStream(out);
  zout.write(bb.array());
  zout.finish();
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:34,代碼來源:TileUtils.java

示例3: c

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
private static String c(String str) {
    String str2 = null;
    try {
        byte[] bytes = str.getBytes(z[5]);
        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        OutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gZIPOutputStream.write(bytes);
        gZIPOutputStream.close();
        bytes = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        str2 = a.a(bytes);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    return str2;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:ac.java

示例4: compress

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
public static final byte[] compress(byte[] bytes)
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
    {
        GZIPOutputStream gzip = new GZIPOutputStream(baos);
        gzip.write(bytes, 0, bytes.length);
        gzip.finish();
        byte[] fewerBytes = baos.toByteArray();
        gzip.close();
        baos.close();
        gzip = null;
        baos = null;
        return fewerBytes;
    }
    catch (IOException e)
    {
        throw new FacesException(e);
    }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:21,代碼來源:StateUtils.java

示例5: compress

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Compress.
 *
 * @param filename
 *            the filename
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private void compress(String filename) throws IOException {
	File current = new File(filename);
	File dir = new File(metricPath);
	FilenameFilter textFileFilter = (f, s) -> s.endsWith(".prom");
	File[] directoryListing = dir.listFiles(textFileFilter);
	if (directoryListing != null) {
		for (File file : directoryListing) {
			if (file.getCanonicalPath() != current.getCanonicalPath()) {
				try (FileOutputStream fos = new FileOutputStream(file.getPath() + ".gz");
						GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
					byte[] buffer = new byte[8192];
					int length;
					try (FileInputStream fis = new FileInputStream(file.getPath())) {
						while ((length = fis.read(buffer)) > 0) {
							gzos.write(buffer, 0, length);
						}
					}
				}
				file.delete();
			}
		}
	} else {
		throw new IOException("Directory not listable: " + metricPath);
	}
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:34,代碼來源:PrometheusFileReporter.java

示例6: save

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Saves current state of the TT (itself).
 *
 * @return <code>true</code> if serialization was successful
 */
public boolean save() {
    try {
        // Save to file
        FileOutputStream oFOS = new FileOutputStream(this.strTableFile);

        // Compressed
        GZIPOutputStream oGZOS = new GZIPOutputStream(oFOS);

        // Save objects
        ObjectOutputStream oOOS = new ObjectOutputStream(oGZOS);

        oOOS.writeObject(this);
        oOOS.flush();
        oOOS.close();

        return true;
    } catch (IOException e) {
        System.err.println("TransitionTable::save() - WARNING: " + e.getMessage());
        e.printStackTrace(System.err);
        return false;
    }
}
 
開發者ID:souhaib100,項目名稱:MARF-for-Android,代碼行數:28,代碼來源:TransitionTable.java

示例7: gzip

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Compresses a GZIP file.
 * 
 * @param bytes The uncompressed bytes.
 * @return The compressed bytes.
 * @throws IOException if an I/O error occurs.
 */
public static byte[] gzip(byte[] bytes) throws IOException {
	/* create the streams */
	InputStream is = new ByteArrayInputStream(bytes);
	try {
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		OutputStream os = new GZIPOutputStream(bout);
		try {
			/* copy data between the streams */
			byte[] buf = new byte[4096];
			int len = 0;
			while ((len = is.read(buf, 0, buf.length)) != -1) {
				os.write(buf, 0, len);
			}
		} finally {
			os.close();
		}

		/* return the compressed bytes */
		return bout.toByteArray();
	} finally {
		is.close();
	}
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:31,代碼來源:CompressionUtils.java

示例8: ScriptWriterText

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
public ScriptWriterText(Database db, String file,
                        boolean includeCachedData, boolean compressed) {

    super(db, file, includeCachedData, true, false);

    if (compressed) {
        isCompressed = true;

        try {
            fileStreamOut = new GZIPOutputStream(fileStreamOut);
        } catch (IOException e) {
            throw Error.error(e, ErrorCode.FILE_IO_ERROR,
                              ErrorCode.M_Message_Pair, new Object[] {
                e.toString(), outFile
            });
        }
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:19,代碼來源:ScriptWriterText.java

示例9: gzipBase64

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Gzips the input then base-64 it.
 *
 * @param path the input data file, as an instance of {@link Path}
 * @return the compressed output, as a String
 */
private static String gzipBase64(Path path) {
  try {
    long size = Files.size(path) / 4 + 1;
    int initialSize = size > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) size;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream(initialSize)) {
      try (OutputStream baseos = Base64.getEncoder().wrap(baos)) {
        try (GZIPOutputStream zos = new GZIPOutputStream(baseos)) {
          Files.copy(path, zos);
        }
      }
      return baos.toString("ISO-8859-1");  // base-64 bytes are ASCII, so this is optimal
    }
  } catch (IOException ex) {
    throw new UncheckedIOException("Failed to gzip base-64 content", ex);
  }
}
 
開發者ID:OpenGamma,項目名稱:JavaSDK,代碼行數:23,代碼來源:PortfolioDataFile.java

示例10: gzipFile

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
private File gzipFile(File src) throws IOException {
    // Never try to make it stream-like on the fly, because content-length still required
    // Create the GZIP output stream
    String outFilename = src.getAbsolutePath() + ".gz";
    notifier.notifyAbout("Gzipping " + src.getAbsolutePath());
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename), 1024 * 8, true);

    // Open the input file
    FileInputStream in = new FileInputStream(src);

    // Transfer bytes from the input file to the GZIP output stream
    byte[] buf = new byte[10240];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    // Complete the GZIP file
    out.finish();
    out.close();

    src.delete();

    return new File(outFilename);
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:27,代碼來源:LoadosophiaAPIClient.java

示例11: main

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
public static void main(String[] args) throws IOException{
    BufferedReader in=new BufferedReader(
            new FileReader("./src/main/java/io/source/data1.txt")
    );
    BufferedOutputStream out=new BufferedOutputStream(new GZIPOutputStream(
            new FileOutputStream("./src/main/java/io/source/data1.gz")
    ));

    System.out.println("Writing file");

    int c;
    while ((c=in.read())!=-1){
        out.write(c);
    }
    in.close();
    out.close();
    System.out.println("Reading file");
    BufferedReader in2=new BufferedReader(
            new InputStreamReader(new GZIPInputStream(
                    new FileInputStream("./src/main/java/io/source/data1.gz"))));
    String s;
    while ((s=in2.readLine())!=null){
        System.out.println(s);
    }

}
 
開發者ID:sean417,項目名稱:LearningOfThinkInJava,代碼行數:27,代碼來源:GZIPcompress.java

示例12: serializeBundle

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
public static String serializeBundle(final Bundle bundle) {
    String base64;
    final Parcel parcel = Parcel.obtain();
    try {
        parcel.writeBundle(bundle);
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(bos));
        zos.write(parcel.marshall());
        zos.close();
        base64 = Base64.encodeToString(bos.toByteArray(), 0);
    } catch (IOException e) {
        e.printStackTrace();
        base64 = null;
    } finally {
        parcel.recycle();
    }
    return base64;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:19,代碼來源:BundleUtil.java

示例13: saveIdfScores

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
/**
 * Saves the IDF scores in a tab-separated format:<br>
 * TOKEN  &emsp; TOKEN_ID &emsp; IDF-SCORE &emsp; FREQUENCY
 * @param idfFile path to the output file
 */
public void saveIdfScores(String idfFile) {
    try {
        Writer out;
        if (idfFile.endsWith(".gz")) {
            out = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(idfFile)), "UTF-8");
        } else {
            out = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(idfFile), "UTF-8"));
        }
        for (String token : tokenIds.keySet()) {
            int tokenId = tokenIds.get(token);
            int frequency = documentFrequency.get(tokenId);
            if (frequency >= minFrequency) {
                double idfScore = Math.log(documentCount / frequency);
                out.write(token + "\t" + tokenId + "\t" + idfScore + "\t" + frequency + "\n");
            }
        }
        out.close();
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
    }

}
 
開發者ID:uhh-lt,項目名稱:LT-ABSA,代碼行數:29,代碼來源:ComputeIdf.java

示例14: save

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
public void save() {
    if (n.modified) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (
                GZIPOutputStream gzipos = new GZIPOutputStream(baos);
                DataOutputStream dos = new DataOutputStream(gzipos);) {

            n.write(dos);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        model.suspensionHook.store(id, baos.toByteArray());
    }
    n.modified = false;
}
 
開發者ID:aika-algorithm,項目名稱:aika,代碼行數:17,代碼來源:Provider.java

示例15: testToBlob_withCompression

import java.util.zip.GZIPOutputStream; //導入依賴的package包/類
@Test
public void testToBlob_withCompression() throws IOException {
  Blob blob = testTarStreamBuilder.toBlob();

  // Writes the BLOB and captures the output.
  ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
  OutputStream compressorStream = new GZIPOutputStream(tarByteOutputStream);
  blob.writeTo(compressorStream);

  // Rearrange the output into input for verification.
  ByteArrayInputStream byteArrayInputStream =
      new ByteArrayInputStream(tarByteOutputStream.toByteArray());
  InputStream tarByteInputStream = new GZIPInputStream(byteArrayInputStream);
  TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);

  verifyTarArchive(tarArchiveInputStream);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:18,代碼來源:TarStreamBuilderTest.java


注:本文中的java.util.zip.GZIPOutputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。