当前位置: 首页>>代码示例>>Java>>正文


Java DeflaterOutputStream.flush方法代码示例

本文整理汇总了Java中java.util.zip.DeflaterOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java DeflaterOutputStream.flush方法的具体用法?Java DeflaterOutputStream.flush怎么用?Java DeflaterOutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.DeflaterOutputStream的用法示例。


在下文中一共展示了DeflaterOutputStream.flush方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compressString

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static String compressString(String s) throws Exception
{
	if(s == null)
	{
		return "";
	}
	
	ByteArrayOutputStream ba = new ByteArrayOutputStream(s.length() * 2 + 20);
	DeflaterOutputStream out = new DeflaterOutputStream(ba);
	byte[] bytes = s.getBytes(CHARSET_UTF8);
	out.write(bytes);
	out.finish();
	out.flush();
	
	byte[] compressed = ba.toByteArray();
	return Hex.toHexString(compressed);
}
 
开发者ID:andy-goryachev,项目名称:FxEditor,代码行数:18,代码来源:CKit.java

示例2: compressDeflate

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private static byte[] compressDeflate(byte[] data)
{
	try {
		ByteArrayOutputStream bout = new ByteArrayOutputStream(500);
		DeflaterOutputStream compresser = new DeflaterOutputStream(bout);
		compresser.write(data, 0, data.length);
		compresser.finish();
		compresser.flush();
		return bout.toByteArray();
	}
	catch (IOException ex) {
		AssertionError ae = new AssertionError("IOException while writing to ByteArrayOutputStream!");
		ae.initCause(ex);
		throw ae;
	}
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:BenchmarkRunner.java

示例3: a

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static byte[] a(byte[] bArr) {
    if (bArr == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream);
    try {
        deflaterOutputStream.write(bArr, 0, bArr.length);
        deflaterOutputStream.finish();
        deflaterOutputStream.flush();
        deflaterOutputStream.close();
        return byteArrayOutputStream.toByteArray();
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:j.java

示例4: processDsl

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private List<String> processDsl() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    dos.write(dsl.getBytes(StandardCharsets.UTF_8));
    dos.flush();
    dos.close();
    bos.flush();
    bos.close();
    String encoded = BaseEncoding.base64Url().encode(bos.toByteArray());
    return split(encoded);
}
 
开发者ID:atlascon,项目名称:travny,代码行数:12,代码来源:Codegen.java

示例5: compressDecompressLoop

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private void compressDecompressLoop(int rawDataSize) throws IOException {
  byte[] rawData = null;
  rawData = generate(rawDataSize);
  ByteArrayOutputStream baos = new ByteArrayOutputStream(rawDataSize+12);
  DeflaterOutputStream dos = new DeflaterOutputStream(baos);
  dos.write(rawData);
  dos.flush();
  dos.close();
  byte[] compressedResult = baos.toByteArray();
  int compressedSize = compressedResult.length;
  ZlibDirectDecompressor decompressor = new ZlibDirectDecompressor();
 
  ByteBuffer inBuf = ByteBuffer.allocateDirect(compressedSize);
  ByteBuffer outBuf = ByteBuffer.allocateDirect(rawDataSize);

  inBuf.put(compressedResult, 0, compressedSize);
  inBuf.flip();    

  ByteBuffer expected = ByteBuffer.wrap(rawData);
  
  outBuf.clear();
  while(!decompressor.finished()) {
    decompressor.decompress(inBuf, outBuf);
    if (outBuf.remaining() == 0) {
      outBuf.flip();
      while (outBuf.remaining() > 0) {        
        assertEquals(expected.get(), outBuf.get());
      }
      outBuf.clear();
    }
  }
  outBuf.flip();
  while (outBuf.remaining() > 0) {        
    assertEquals(expected.get(), outBuf.get());
  }
  outBuf.clear();
  
  assertEquals(0, expected.remaining());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:40,代码来源:TestZlibCompressorDecompressor.java

示例6: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
@Override
public void compress(InputStream uncompressedIn, OutputStream compressedOut) throws IOException {
  byte[] buffer = new byte[inputBufferSize];
  DeflaterOutputStream deflaterOut =
      new DeflaterOutputStream(compressedOut, createOrResetDeflater(), outputBufferSize);
  int numRead = 0;
  while ((numRead = uncompressedIn.read(buffer)) >= 0) {
    deflaterOut.write(buffer, 0, numRead);
  }
  deflaterOut.finish();
  deflaterOut.flush();
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:13,代码来源:DeflateCompressor.java

示例7: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
/**
 * 压缩
 * 
 * @param data 待压缩的数据
 * @param os 输出流
 * @throws IOException
 */
public static void compress(byte[] data, OutputStream os) throws IOException
{
	DeflaterOutputStream dos = new DeflaterOutputStream(os);

	dos.write(data, 0, data.length);
	dos.finish();
	dos.flush();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:16,代码来源:ZLibUtils.java

示例8: toCompressedBytes

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static byte[] toCompressedBytes(@Nonnull final Object obj) throws IOException {
    FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    try {
        toStream(obj, dos);
        dos.finish();
        dos.flush();
        return bos.toByteArray_clear();
    } finally {
        IOUtils.closeQuietly(dos);
    }
}
 
开发者ID:apache,项目名称:incubator-hivemall,代码行数:13,代码来源:ObjectUtils.java

示例9: main

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	
	//Open scanner
       Scanner reader = new Scanner(System.in);
	
	//file?
       System.err.println("What midi file do you want to parse?");
       System.err.print("[file] > ");
       File file = new File(reader.nextLine());
       
       //speakers?
       System.err.println("Also include speakers?");
       System.err.println("[y/n] (Y)");
       boolean speakers = !reader.nextLine().trim().equals("n");
       
       //parse the song
	Data data = Midi.parse(reader, file);
	
	List<Note> notes = data.notes;
	List<Sound> tracks = data.tracks;
	
	//create combinators
	List<Combinator> combinators = Generate.combinators(notes);

	//Sort the combinators based on tick
	Collections.sort(combinators, new Comparator<Combinator>() {
		public int compare(Combinator o1, Combinator o2) {
			return o1.tick - o2.tick;
		}
	});
	
	//create ROM
	JSONArray rom = new JSONArray();
	
	//build the main clock
	Generate.clock(rom, combinators);
	
	//position array of giant combinators
	int maxHeight = (int) Math.sqrt(combinators.size()) * 2;
	int maxWidth = Position.combinators(rom, maxHeight, combinators);
	
	//position substation within ROM
	int id = Position.substations(rom, maxWidth, maxHeight, combinators.get(combinators.size() - 1).getDeciderId());
	
	//place speakers
	if(speakers) Position.speakers(rom, id, tracks);
	
	//build the blueprint
	JSONObject blueprint = Generate.blueprint(rom, file);
	
	//print raw blueprint
	System.out.println();
	System.out.println("Blueprint: ");
	System.out.println("(hidden)");
	//System.out.println(blueprint);
	
	//compress blueprint
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
       DeflaterOutputStream dos = new DeflaterOutputStream(baos);
       dos.write(blueprint.toString().getBytes());
       dos.flush();
       dos.close();
       System.out.println();
       System.out.println("Blueprint String: ");
       System.out.println(VERSION + new String(Base64.getEncoder().encode(baos.toByteArray())));
	
       //print some neat statistics
	System.out.println();
	System.out.println("Stats: ");
	System.out.printf("Your song has %d notes, %d combinators, and %d tracks!\n", notes.size(), combinators.size(), tracks.size());
	
	reader.close();
}
 
开发者ID:RedInquisitive,项目名称:Midi-Factorio,代码行数:74,代码来源:Main.java


注:本文中的java.util.zip.DeflaterOutputStream.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。