Refine search
@Override public void readOSM(OpenStreetMapContentHandler handler) { try { OpenStreetMapParser parser = new OpenStreetMapParser(); if (path.getName().endsWith(".gz")) { InputStream in = new GZIPInputStream(new FileInputStream(path)); parser.parseMap(in, handler); } else if (path.getName().endsWith(".bz2")) { BZip2CompressorInputStream in = new BZip2CompressorInputStream(new FileInputStream(path)); parser.parseMap(in, handler); } else { parser.parseMap(path, handler); } } catch (Exception ex) { throw new IllegalStateException("error loading OSM from path " + path, ex); } }
FileInputStream in = new FileInputStream("archive.tar.bz2"); FileOutputStream out = new FileOutputStream("archive.tar"); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); final byte[] buffer = new byte[buffersize]; int n = 0; while (-1 != (n = bzIn.read(buffer))) { out.write(buffer, 0, n); } out.close(); bzIn.close();
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array()); BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int readCount = -1; while ( (readCount = inputStream.read(buffer, compressedData.position(), buffer.length))> 0) { baos.write(buffer, 0, readCount); } ByteBuffer result = ByteBuffer.wrap(baos.toByteArray()); return result; } finally { inputStream.close(); } }
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array(), computeOffset(compressedData), compressedData.remaining()); try(BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int readCount = -1; while ((readCount = inputStream.read(buffer, compressedData.position(), buffer.length)) > 0) { baos.write(buffer, 0, readCount); } return ByteBuffer.wrap(baos.toByteArray()); } }
fis = new FileInputStream(archive); } catch (FileNotFoundException ex) { final String msg = String.format("Error extracting file `%s`: %s", archive.getAbsolutePath(), ex.getMessage()); bzin = new BZip2CompressorInputStream(in); decompressFile(bzin, f);
fs = new FileInputStream(inputFile); this.fc = fs.getChannel(); this.fileSize = fc.size(); if (fileSize > 0) { parser.parse(new InputSource(fs)); } else if (inputFile.getName().endsWith(".osm.gz")) { parser.parse(new InputSource(new GZIPInputStream(fs))); } else if (inputFile.getName().endsWith(".osm.bz2")) { parser.parse(new InputSource(new BZip2CompressorInputStream(fs))); } else { throw new SQLException("Supported formats are .osm, .osm.gz, .osm.bz2"); try { if (fs != null) { fs.close();
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip) throws IOException { int MAX_DATA_SIZE = 1024 * 1024; byte[] data = new byte[MAX_DATA_SIZE]; FileInputStream fis = new FileInputStream(testFileUrl.getFile()); int count; if (bzip) { BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis); count = bzIn.read(data); bzIn.close(); } else { count = fis.read(data); } fis.close(); assertTrue("Test file data too big for buffer", count < data.length); return new String(data, 0, count, "UTF-8").split("\n"); }
try (FileInputStream fis = new FileInputStream(destination)) { final byte[] actualBz2 = new byte[bz2.length]; int n = 0; int offset = 0; do { n = fis.read(actualBz2, offset, actualBz2.length - offset); offset += n; } while (offset < actualBz2.length); try (BZip2CompressorInputStream bzin = new BZip2CompressorInputStream(new ByteArrayInputStream(bz2))) { final StringBuilder sb = new StringBuilder(); final byte[] buf = new byte[1024]; int n = 0; while ((n = bzin.read(buf, 0, buf.length)) > -1) { sb.append(new String(buf, 0, n));
BZip2CompressorInputStream compressedInputStream = new BZip2CompressorInputStream(new FileInputStream (dumpFile)); blobLog.close(); compressedInputStream.close();
String s = CompressorStreamFactory.detect(buffered); if (s.equals(CompressorStreamFactory.GZIP)) { in = new GZIPInputStream(buffered); } else if (s.equals(CompressorStreamFactory.LZMA)) { in = new LZMACompressorInputStream(buffered); } else if (s.equals(CompressorStreamFactory.BZIP2)) { in = new BZip2CompressorInputStream(buffered);
@Override public BZip2CompressorInputStream create(InputStream in) throws IOException { return new BZip2CompressorInputStream(in); }
bzipIn = new BZip2CompressorInputStream(request.getSourceInputStream()); bzRequest.open(bzipIn); final IdentificationResultCollection bzResults = if (bzipIn != null) { try { bzipIn.close(); } catch (IOException ioe) { throw new CommandExecutionException(ioe.getMessage(), ioe);
@Override public CompressorInputStream open(File compressedFile) throws IOException { InputStream is = new FileInputStream(compressedFile); try { return new BZip2CompressorInputStream(is); } catch (IOException ioe) { try { is.close(); } catch (Exception e) {} throw ioe; } }
fs = new FileInputStream(inputFile); this.fc = fs.getChannel(); this.fileSize = fc.size(); parser.parse(new InputSource(fs)); } else if(inputFile.getName().endsWith(".osm.gz")) { parser.parse(new InputSource(new GZIPInputStream(fs))); } else if(inputFile.getName().endsWith(".osm.bz2")) { parser.parse(new InputSource(new BZip2CompressorInputStream(fs))); try { if (fs != null) { fs.close();
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip) throws IOException { int MAX_DATA_SIZE = 1024 * 1024; byte[] data = new byte[MAX_DATA_SIZE]; FileInputStream fis = new FileInputStream(testFileUrl.getFile()); int count; if (bzip) { BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis); count = bzIn.read(data); bzIn.close(); } else { count = fis.read(data); } fis.close(); assertTrue("Test file data too big for buffer", count < data.length); return new String(data, 0, count, "UTF-8").split("\n"); }
return Streams.bufferedInputStream( new GZIPInputStream( istream ) ); return new BZip2CompressorInputStream( istream );
@Override protected InputStream createInputStream(InputStream in) throws IOException { return new BZip2CompressorInputStream(in); } };
@Override ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array()); BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int readCount = -1; while ( (readCount = inputStream.read(buffer, compressedData.position(), buffer.length))> 0) { baos.write(buffer, 0, readCount); } ByteBuffer result = ByteBuffer.wrap(baos.toByteArray()); return result; } finally { inputStream.close(); } }
@Override public long decompress(InputStream is, OutputStream os, long maxLength, long maxCheckSizeBytes) throws IOException, CompressionOutputSizeException { BZip2CompressorInputStream bz2is = new BZip2CompressorInputStream(HeaderStreams.augInput(BZ_HEADER, is)); long written = 0; int bufSize = 32768; int bytesRead = bz2is.read(buffer, 0, buffer.length); if(expectedBytesRead < bytesRead) { Logger.normal(this, "expectedBytesRead="+expectedBytesRead+", bytesRead="+bytesRead+", written="+written+", maxLength="+maxLength+" throwing a CompressionOutputSizeException"); while(true) { expectedBytesRead = (int) Math.min(buffer.length, maxLength + maxCheckSizeBytes - written); bytesRead = bz2is.read(buffer, 0, expectedBytesRead); if(bytesRead <= -1) throw new CompressionOutputSizeException(written); if(bytesRead == 0) throw new IOException("Returned zero from read()");
@Override public void readOSM(OpenStreetMapContentHandler handler) { try { if (path.getName().endsWith(".gz")) { InputStream in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 1); handler.doneFirstPhaseRelations(); in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 2); handler.doneSecondPhaseWays(); in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 3); handler.doneThirdPhaseNodes(); } else if (path.getName().endsWith(".bz2")) { InputStream in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 1); handler.doneFirstPhaseRelations(); in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 2); handler.doneSecondPhaseWays(); in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 3); handler.doneThirdPhaseNodes(); } else { StreamedOpenStreetMapParser.parseMap(path, handler); } } catch (Exception ex) { throw new IllegalStateException("error loading OSM from path " + path, ex); } }