本文整理汇总了Java中org.itadaki.bzip2.BZip2InputStream类的典型用法代码示例。如果您正苦于以下问题:Java BZip2InputStream类的具体用法?Java BZip2InputStream怎么用?Java BZip2InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BZip2InputStream类属于org.itadaki.bzip2包,在下文中一共展示了BZip2InputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decompress
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
public static File decompress(File inputFile) throws IOException {
if (!inputFile.exists() || !inputFile.canRead() || !inputFile.getName().endsWith(".bz2")) {
throw new IOException("Cannot read file " + inputFile.getPath());
}
File outputFile = new File(inputFile.toString().substring(0, inputFile.toString().length() - 4));
if (outputFile.exists()) {
throw new FileAlreadyExistsException(outputFile.toString());
}
try (InputStream fileInputStream = new BufferedInputStream(new FileInputStream(inputFile));
BZip2InputStream inputStream = new BZip2InputStream(fileInputStream, false);
OutputStream fileOutputStream = new BufferedOutputStream(new FileOutputStream(outputFile), 524288)) {
byte[] decoded = new byte[524288];
int bytesRead;
while ((bytesRead = inputStream.read(decoded)) != -1) {
fileOutputStream.write(decoded, 0, bytesRead);
}
}
return outputFile;
}
示例2: compile
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
static void compile(String file, String database){
DB db = DBMaker.newFileDB(new File(database)).compressionEnable().closeOnJvmShutdown().make();
NavigableSet<Tuple2<String, Tuple2<String,Double>>> multiset = db.getTreeSet("SW");
multiset.clear();
try {
BufferedReader swFile = new BufferedReader(new InputStreamReader(new BZip2InputStream(new FileInputStream(new File(file)), false), "UTF-8"));
int entry = 0;
for(String line=swFile.readLine();line != null;line = swFile.readLine()){
String key = line.trim();
String[] values = swFile.readLine().trim().split(" ");
for(int i = 1;i < values.length;i += 2){
multiset.add(Fun.t2(key, Fun.t2(values[i-1], Double.parseDouble(values[i]))));
}
if(entry++ > 100){
db.commit();
entry = 0;
}
}
swFile.close();
} catch (IOException e) {
e.printStackTrace();
}
db.commit();
db.close();
}
示例3: 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();
}
示例4: testEmpty
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @throws IOException
*/
@Test
public void testEmpty() throws IOException {
byte[] testData = new byte [0];
// Compress
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
BZip2OutputStream output = new BZip2OutputStream (byteOutput);
output.write (testData);
output.close();
// Test EOF
ByteArrayInputStream byteInput = new ByteArrayInputStream (byteOutput.toByteArray());
BZip2InputStream input = new BZip2InputStream (byteInput, false);
assertEquals (-1, input.read());
}
示例5: testOneByte
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @throws IOException
*/
@Test
public void testOneByte() throws IOException {
byte[] testData = new byte[] { 'A' };
// 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());
}
示例6: testTwoBytes
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @throws IOException
*/
@Test
public void testTwoBytes() throws IOException {
byte[] testData = new byte[] { 'B', 'A' };
// 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());
}
示例7: 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());
}
示例8: 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());
}
示例9: 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());
}
示例10: 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());
}
示例11: testExceptionDuringClose
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* Test coverage : InputStream throws an exception during BZip2InputStream.close()
* @throws IOException
*/
@Test(expected=IOException.class)
public void testExceptionDuringClose() 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()) {
@Override
public void close() throws IOException {
throw new IOException();
}
};
BZip2InputStream input = new BZip2InputStream (byteInput, false);
// Test
input.close();
}
示例12: test4Tables
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @throws IOException
*/
@Test
public void test4Tables() throws IOException {
byte[] testData = new byte [1100];
// 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());
}
示例13: 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());
}
示例14: 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());
}
示例15: testDecompressionBug2
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @throws IOException
*/
@Test
public void testDecompressionBug2() throws IOException {
byte[] testData = new byte [0];
// 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);
// Compare
assertEquals (-1, input.read());
assertEquals (-1, input.read());
}