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


Java BZip2InputStream.read方法代码示例

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


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

示例1: decompress

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
@Override
public byte[] decompress(byte[] toDecompress) {
	InputStream fileInputStream = new ByteArrayInputStream(toDecompress);
       BZip2InputStream inputStream = new BZip2InputStream(fileInputStream, false);
       ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream();
       byte[] decoded = new byte [readBufferSize];
       int bytesRead;
       try {
        while ((bytesRead = inputStream.read (decoded)) != -1) {
                fileOutputStream.write(decoded, 0, bytesRead) ;        
        }
        fileOutputStream.close();
        inputStream.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return fileOutputStream.toByteArray();
}
 
开发者ID:iostackproject,项目名称:SDGen,代码行数:19,代码来源:BzipCompression.java

示例2: testCompressionBug1

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testCompressionBug1() throws IOException {

	byte[] testData = new byte [4];

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read (decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals (testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java

示例3: testRegular1

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testRegular1() throws IOException {

	byte[] testData = "Mary had a little lamb, its fleece was white as snow".getBytes();

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read(decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals(testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java

示例4: testRegular2

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testRegular2() throws IOException {

	byte[] testData = "Mary had a little lamb, its fleece was white as snow".getBytes();

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	for (int i = 0; i < testData.length; i++) {
		output.write (testData[i]);
	}
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read(decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals(testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:28,代码来源:TestBZip2OutputStream.java

示例5: testHeaderless

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testHeaderless() throws IOException {

	byte[] testData = "Mary had a little lamb, its fleece was white as snow".getBytes();

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	ByteArrayInputStream byteInput = new ByteArrayInputStream (Arrays.copyOfRange (compressedData, 2, compressedData.length));
	BZip2InputStream input = new BZip2InputStream (byteInput, true);
	byte[] decodedTestData = new byte [testData.length];
	input.read(decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals(testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:27,代码来源:TestBZip2OutputStream.java

示例6: testReadPastEnd

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testReadPastEnd() throws IOException {

	byte[] testData = "Mary had a little lamb, its fleece was white as snow".getBytes();

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read(decodedTestData, 0, decodedTestData.length);

	// Test
	assertEquals (-1, input.read());
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java

示例7: testLongBlank

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testLongBlank() throws IOException {

	// Blank test block
	byte[] testData = new byte [100000];

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read (decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals (testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:27,代码来源:TestBZip2OutputStream.java

示例8: testLongSame

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testLongSame() throws IOException {

	byte[] testData = new byte [100000];

	// Create test block
	Arrays.fill (testData, (byte)123);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read (decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals (testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:29,代码来源:TestBZip2OutputStream.java

示例9: testInvalidStartPointer

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testInvalidStartPointer() throws IOException {

	// Create test block
	byte[] testData = new byte [1000];
	Random random = new Random (1234);
	random.nextBytes (testData);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	compressedData[14] = -1;
	ByteArrayInputStream byteInput = new ByteArrayInputStream (compressedData);
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	try {
		input.read (decodedTestData, 0, decodedTestData.length);
		input.read();
		fail();
	} catch (IOException e) {
		assertEquals ("BZip2 start pointer invalid", e.getMessage());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:36,代码来源:TestBZip2OutputStream.java

示例10: testInvalidBlockSize2

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testInvalidBlockSize2() throws IOException {

	// Create test block
	byte[] testData = new byte [200000];
	Random random = new Random (1234);
	random.nextBytes (testData);
	Arrays.fill(testData, 100000, testData.length, (byte)0);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	compressedData[3] = '1';
	ByteArrayInputStream byteInput = new ByteArrayInputStream (compressedData);
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	try {
		input.read (decodedTestData, 0, decodedTestData.length);
		fail();
	} catch (IOException e) {
		assertEquals ("BZip2 block exceeds declared block size", e.getMessage());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:36,代码来源:TestBZip2OutputStream.java

示例11: testInvalidHeader

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testInvalidHeader() throws IOException {

	// Create test block
	byte[] testData = new byte [1000];
	Random random = new Random (1234);
	random.nextBytes (testData);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	compressedData[0] = '1';
	ByteArrayInputStream byteInput = new ByteArrayInputStream (compressedData);
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	try {
		input.read (decodedTestData, 0, decodedTestData.length);
		fail();
	} catch (IOException e) {
		assertEquals ("Invalid BZip2 header", e.getMessage());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:35,代码来源:TestBZip2OutputStream.java

示例12: testReadAfterClose

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testReadAfterClose() throws IOException {

	byte[] testData = "Mary had a little lamb, its fleece was white as snow".getBytes();

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);

	// Test
	input.close();
	try {
		input.read();
	} catch (IOException e) {
		assertEquals ("Stream closed", e.getMessage());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:31,代码来源:TestBZip2OutputStream.java

示例13: testInvalidHeaderSecondRead

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testInvalidHeaderSecondRead() throws IOException {

	// Create test block
	byte[] testData = new byte [1000];
	Random random = new Random (1234);
	random.nextBytes (testData);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	compressedData[0] = '1';
	ByteArrayInputStream byteInput = new ByteArrayInputStream (compressedData);
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	try {
		input.read (decodedTestData, 0, decodedTestData.length);
		fail();
	} catch (IOException e) {
		assertEquals (-1, input.read());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:35,代码来源:TestBZip2OutputStream.java

示例14: testInvalidBlockSize1

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void testInvalidBlockSize1() throws IOException {

	// Create test block
	byte[] testData = new byte [200000];
	Random random = new Random (1234);
	random.nextBytes (testData);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	byte[] compressedData = byteOutput.toByteArray();
	compressedData[3] = '1';
	ByteArrayInputStream byteInput = new ByteArrayInputStream (compressedData);
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	try {
		input.read (decodedTestData, 0, decodedTestData.length);
		fail();
	} catch (IOException e) {
		assertEquals ("BZip2 block exceeds declared block size", e.getMessage());
		return;
	}

	fail();

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:35,代码来源:TestBZip2OutputStream.java

示例15: test5Tables

import org.itadaki.bzip2.BZip2InputStream; //导入方法依赖的package包/类
/**
 * @throws IOException 
 */
@Test
public void test5Tables() throws IOException {

	byte[] testData = new byte [2300];

	// Create test block
	Random random = new Random (1234);
	random.nextBytes (testData);

	// Compress
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	BZip2OutputStream output = new BZip2OutputStream (byteOutput);
	output.write (testData);
	output.close();

	// Decompress
	ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
	BZip2InputStream input = new BZip2InputStream (byteInput, false);
	byte[] decodedTestData = new byte [testData.length];
	input.read (decodedTestData, 0, decodedTestData.length);

	// Compare
	assertArrayEquals (testData, decodedTestData);
	assertEquals (-1, input.read());

}
 
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:30,代码来源:TestBZip2OutputStream.java


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