当前位置: 首页>>代码示例>>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;未经允许,请勿转载。