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


Java FilterOutputStream.close方法代碼示例

本文整理匯總了Java中java.io.FilterOutputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java FilterOutputStream.close方法的具體用法?Java FilterOutputStream.close怎麽用?Java FilterOutputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.FilterOutputStream的用法示例。


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

示例1: writeZipFile

import java.io.FilterOutputStream; //導入方法依賴的package包/類
private void writeZipFile(File baseDir, File archive, List<String> files) throws FileNotFoundException, IOException {
	FilterOutputStream out = null;
	ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(archive));
	stream.setLevel(Deflater.DEFAULT_COMPRESSION);
	out = stream;

	byte data[] = new byte[18024];

	for (String f : files) {
		logger.info(String.format("Writing %s to ZIP archive %s", f, archive));
		((ZipOutputStream) out).putNextEntry(new ZipEntry(f));

		BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(baseDir, f)));

		int len = 0;
		while ((len = in.read(data)) > 0) {
			out.write(data, 0, len);
		}

		out.flush();
		in.close();
	}

	out.close();
}
 
開發者ID:lizardtechblog,項目名稱:ExpressZip,代碼行數:26,代碼來源:Job.java

示例2: test_close

import java.io.FilterOutputStream; //導入方法依賴的package包/類
/**
 * @tests java.io.FilterOutputStream#close()
 */
public void test_close() throws IOException {
    bos = new ByteArrayOutputStream();
    os = new FilterOutputStream(bos);
    os.write(fileString.getBytes(), 0, 500);
    os.flush();
    assertEquals("Bytes not written after flush", 500, bos.size());
    os.close();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:12,代碼來源:FilterOutputStreamTest.java

示例3: test_flush

import java.io.FilterOutputStream; //導入方法依賴的package包/類
/**
 * @tests java.io.FilterOutputStream#flush()
 */
public void test_flush() throws IOException {
    bos = new ByteArrayOutputStream();
    os = new FilterOutputStream(bos);
    os.write(fileString.getBytes(), 0, 500);
    os.flush();
    assertEquals("Bytes not written after flush", 500, bos.size());
    os.close();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:12,代碼來源:FilterOutputStreamTest.java

示例4: testIt

import java.io.FilterOutputStream; //導入方法依賴的package包/類
@Test
public void testIt() throws IOException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
	Shake128 shake128 = new Shake128();
	SecureRandom keyRandom = new SecureRandom();
	Random dataRandom = new Random();
	byte[] key = new byte[128];
	keyRandom.nextBytes(key);
	
	for(int i=8; i < 16384; ++i) {
		byte[] data = new byte[i];			
		byte[] nonce = new byte[128];
		keyRandom.nextBytes(nonce);
		dataRandom.nextBytes(data);
		
		shake128.getAbsorbStream().write(key);
		shake128.getAbsorbStream().write(nonce);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		FilterOutputStream fos = shake128.getTransformingSqueezeStream(bos);
		fos.write(data);
		fos.close();
		Assert.assertTrue(bos.size()==data.length);
		Assert.assertTrue(!Arrays.equals(data, bos.toByteArray()));
		
		byte[] encrypted = bos.toByteArray();
		
		shake128.reset();
		shake128.getAbsorbStream().write(key);
		shake128.getAbsorbStream().write(nonce);
		bos.reset();
		fos = shake128.getTransformingSqueezeStream(bos);
		fos.write(encrypted);
		fos.close();
		byte[] decrypted = bos.toByteArray();
		Assert.assertTrue(data != decrypted);
		Assert.assertTrue(Arrays.equals(decrypted, data));				
		
		// Using the SPI impl. getCipher not available unless Jar is signed	
		IvParameterSpec ivParameterSpec = new IvParameterSpec(nonce);
		Shake128Key shakeKey = new Shake128Key();
		shakeKey.setRaw(key);
		Shake128StreamCipher c  = new Shake128StreamCipher();
		c.init(Cipher.ENCRYPT_MODE, shakeKey, ivParameterSpec);
		byte[] encrypted2 = c.doFinal(data);
		Assert.assertArrayEquals(encrypted, encrypted2);
		c.init(Cipher.DECRYPT_MODE, shakeKey, ivParameterSpec);
		byte[] decrypted2 = c.doFinal(encrypted2);
		Assert.assertArrayEquals(decrypted2, data);
	}
	
	System.out.println("Encryption OK");

	
}
 
開發者ID:aelstad,項目名稱:keccakj,代碼行數:54,代碼來源:TestStreamEncryption.java


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