本文整理汇总了Java中org.itadaki.bzip2.BZip2InputStream类的典型用法代码示例。如果您正苦于以下问题:Java BZip2InputStream类的具体用法?Java BZip2InputStream怎么用?Java BZip2InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BZip2InputStream类属于org.itadaki.bzip2包,在下文中一共展示了BZip2InputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:21,代码来源:BZip2Decompressor.java
示例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();
}
开发者ID:tticoin,项目名称:JointER,代码行数:26,代码来源:NICTNounSynonymsDB.java
示例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();
}
开发者ID:iostackproject,项目名称:SDGen,代码行数:19,代码来源:BzipCompression.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:21,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:28,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:27,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:26,代码来源:TestBZip2OutputStream.java
示例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();
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:29,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:29,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:27,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:29,代码来源:TestBZip2OutputStream.java
示例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());
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:24,代码来源:TestBZip2OutputStream.java
示例16: 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
示例17: FastQFile
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
protected FastQFile(FastQCConfig config,File file) throws SequenceFormatException, IOException {
this.file = file;
if (file.getName().equals("stdin")) {
fileSize = Long.MAX_VALUE;
}
else {
fileSize = file.length();
}
name = file.getName();
if (config.casava) {
casavaMode = true;
if (config.nofilter) {
nofilter = true;
}
}
if (!file.getName().equals("stdin")) {
fis = new FileInputStream(file);
}
if (file.getName().equals("stdin")) {
br = new BufferedReader(new InputStreamReader(System.in));
}
else if (file.getName().toLowerCase().endsWith(".gz")) {
br = new BufferedReader(new InputStreamReader(new MultiMemberGZIPInputStream(fis)));
}
else if (file.getName().toLowerCase().endsWith(".bz2")) {
br = new BufferedReader(new InputStreamReader(new BZip2InputStream(fis,false)));
}
else {
br = new BufferedReader(new InputStreamReader(fis));
}
readNext();
}
开发者ID:golharam,项目名称:FastQC,代码行数:37,代码来源:FastQFile.java
示例18: createInstall
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* Creates a full-fledged installation by downloading a map of the
* governmental district of Karlsruhe from {@code geofabrik.de} and
* executing a precalculation for {@link Profile#defaultCar}.
* <p>
* {@link MapManager} and {@link ProfileMapManager} are expected to have
* been initialized already.
*
* @param rootDir
* The root directory of the routeKIT installation.
* @param pr
* The {@link ProgressReporter} to report progress to.
*/
public static void createInstall(File rootDir, ProgressReporter pr)
throws IOException, SAXException {
pr.setSubTasks(new float[] { .05f, .05f, .9f });
pr.pushTask("Lade Standardkarte herunter");
URL url = new URL(
"http://download.geofabrik.de/europe/germany/baden-wuerttemberg/karlsruhe-regbez-latest.osm.bz2");
File file = File.createTempFile("routeKIT_map_", ".osm");
try (InputStream is = new BZip2InputStream(url.openStream(), false);
FileOutputStream fos = new FileOutputStream(file)) {
byte[] data = new byte[65536];
while (true) {
int read = is.read(data);
if (read == -1) {
break;
}
fos.write(data, 0, read);
}
pr.nextTask("Importiere und speichere Standardkarte");
StreetMap karlsruhe_big = new OSMMapImporter().importMap(file,
"Karlsruhe", pr);
MapManager.getInstance().saveMap(karlsruhe_big);
Properties p = new Properties();
p.setProperty("default", "true");
try (FileWriter writer = new FileWriter(new File(new File(rootDir,
"Karlsruhe"), "Karlsruhe.properties"))) {
p.store(writer, null);
}
pr.nextTask("Erstelle Standard-Vorberechnung");
ProfileMapCombination karlsruheCar = new ProfileMapCombination(
karlsruhe_big, Profile.defaultCar);
new PreCalculator().doPrecalculation(karlsruheCar, pr);
ProfileMapManager.getInstance().setCurrentCombination(karlsruheCar);
ProfileMapManager.getInstance().savePrecalculation(karlsruheCar);
pr.popTask();
}
}
开发者ID:routeKIT,项目名称:routeKIT,代码行数:51,代码来源:Dummies.java
示例19: roundTrip
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* Compresses and decompresses each of a list of files, using a temporary file to hold the compressed data
* @param files The files to compress
* @throws IOException On any error compressing or decompressing the files
*/
private static void roundTrip (List<File> files) throws IOException {
File tempFile = File.createTempFile ("rtr", ".tmp");
for (File inputFile : files) {
long inputLength = inputFile.length();
System.out.print (inputLength + " " + inputFile);
// Compress file
InputStream fileInputStream = new BufferedInputStream (new FileInputStream (inputFile));
OutputStream compressedOutputStream = new BufferedOutputStream (new FileOutputStream (tempFile));
BZip2OutputStream bzip2OutputStream = new BZip2OutputStream (compressedOutputStream);
byte[] buffer = new byte [524288];
int bytesRead;
while ((bytesRead = fileInputStream.read (buffer, 0, buffer.length)) != -1) {
bzip2OutputStream.write (buffer, 0, bytesRead);
}
bzip2OutputStream.close();
compressedOutputStream.close();
fileInputStream.close();
long compressedLength = tempFile.length();
System.out.printf(" (%.1f%%)\n", ((float)(inputLength - compressedLength) / inputLength) * 100);
// Decompress file
InputStream compressedInputStream = new BufferedInputStream (new FileInputStream (tempFile));
BZip2InputStream bzip2InputStream = new BZip2InputStream (compressedInputStream, false);
byte[] decoded = new byte [524288];
while ((bytesRead = bzip2InputStream.read (decoded)) != -1);
compressedInputStream.close();
bzip2InputStream.close();
}
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:44,代码来源:RoundTrip.java
示例20: main
import org.itadaki.bzip2.BZip2InputStream; //导入依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main (String[] args) throws IOException {
if (args.length == 0) {
System.err.println ("Demonstration BZip2 decompressor\n\nUsage:\n java demo.Decompress <filename>\n");
System.exit (1);
}
File inputFile = new File (args[0]);
if (!inputFile.exists() || !inputFile.canRead() || !args[0].endsWith(".bz2")) {
System.err.println ("Cannot read file " + inputFile.getPath());
System.exit (1);
}
File outputFile = new File (args[0].substring (0, args[0].length() - 4));
if (outputFile.exists()) {
System.err.println ("File " + outputFile.getPath() + " already exists");
System.exit (1);
}
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) ;
}
fileOutputStream.close();
}
开发者ID:buttnerchristopher,项目名称:maven-jbzip2,代码行数:36,代码来源:Decompress.java
注:本文中的org.itadaki.bzip2.BZip2InputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论