Java Util Zip Zipinputstream Example
Best Java code snippets using java.util.zip.ZipInputStream.read (Showing top 20 results out of 3,987)
Refine search
private void extractFile(ZipInputStream zipIn, File filePath) throws IOException { try (BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream (filePath))) { byte [] bytesIn = new byte[ 1024 ]; int read; while ((read = zipIn. read (bytesIn)) != - 1 ) { bos.write(bytesIn, 0 , read); } } }
private static byte [] unzipBytes( byte [] input) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(input); ByteArrayOutputStream baos = new ByteArrayOutputStream(DFLT_BUFFER_SIZE); try (ZipInputStream zis = new ZipInputStream (bais)) { zis. getNextEntry (); byte [] buf = new byte[DFLT_BUFFER_SIZE]; int len = zis. read (buf); while (len > 0 ) { baos.write(buf, 0 , len); len = zis. read (buf); } } return baos.toByteArray(); }
@Override public Chunk read() throws IOException { ZipEntry entry = zipIn. getNextEntry (); if (entry == null) { return null; } int read; ByteArrayOutputStream contentByteArray = new ByteArrayOutputStream(); while (- 1 != (read = zipIn. read ())) { contentByteArray.write(read); } return new Chunk(StringUtil.fromHex(entry. getName ()), contentByteArray.toByteArray(), contentByteArray.size(), null); }
public static void decompress(InputStream input, File destDir) throws IOException { ZipInputStream zin = new ZipInputStream (input); ZipEntry entry = null; byte [] buffer = new byte[ 1024 ]; while ((entry = zin. getNextEntry ()) != null) { File f = getZipOutputFile(destDir, entry); if (entry.isDirectory()) { f.mkdirs(); continue ; } BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream (f)); int n = - 1 ; while ((n = zin. read (buffer)) != - 1 ) { out.write(buffer, 0 , n); } out.flush(); out.close(); } }
private void updateGuidZipEntryMap() throws IOException { ZipInputStream zipInputStream = new ZipInputStream (inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { String entryName = zipEntry. getName ().replace( ".json" , "" ); if (guidEntityJsonMap.containsKey(entryName)) continue ; byte [] buf = new byte[ 1024 ]; int n = 0 ; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((n = zipInputStream. read (buf, 0 , 1024 )) > - 1 ) { bos.write(buf, 0 , n); } guidEntityJsonMap.put(entryName, bos.toString()); zipEntry = zipInputStream.getNextEntry(); } zipInputStream.close(); }
@Override public int read() throws IOException { int result = zipInputStream. read (); while (result == - 1 ) { currentEntry = zipInputStream. getNextEntry (); if (currentEntry == null) { return - 1 ; } else { result = zipInputStream. read (); } } return result; }
private void unzipAndSaveImage(ZipInputStream zis, ZipEntry zipEntry) throws IOException { if (zipEntry.isDirectory() || zipEntry. getName ().contains( "__MACOSX" )) { return ; } byte [] buffer = new byte[ 2048 ]; ByteArrayOutputStream output = new ByteArrayOutputStream(); int len; while ((len = zis. read (buffer)) > 0 ) { output.write(buffer, 0 , len); } imageRepository.saveImage(output.toByteArray(), zipEntry. getName ()); } }
static public void recieveZipFile(ZipInputStream zis, String relativePath) throws Exception { ZipEntry zipEntry = null; int readSize; byte [] buffer = new byte[FILE_BUFFER_SIZE]; while (null != (zipEntry = zis. getNextEntry ())){ File outFile = new File(relativePath + "/" + zipEntry. getName ()); File parentFolder = outFile.getParentFile(); if (parentFolder.exists() == false ){ parentFolder.mkdirs(); } BufferedOutputStream fos = null; try { fos = new BufferedOutputStream( new FileOutputStream (outFile)); while ((readSize = zis. read (buffer)) > 0 ){ fos.write(buffer, 0 , readSize); } fos.flush(); } finally { if (fos != null){ try { fos.close(); } catch (Exception ex){} } } } }
private void extractFile(ZipInputStream inputStream, File outputFile) throws Exception { byte [] bytes = new byte[ 1024 ]; try (FileOutputStream outputStream = new FileOutputStream (outputFile)) { int read; while ((read = inputStream. read (bytes)) != - 1 ) { outputStream.write(bytes, 0 , read); } } }
@SuppressWarnings( "unchecked" ) public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { ZIPCompressedMessage result = new ZIPCompressedMessage(); byte [] byteArray = new byte[data.remaining()]; data.get(byteArray); ZipInputStream in = new ZipInputStream ( new ByteArrayInputStream(byteArray)); in. getNextEntry (); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte [] tmp = new byte[ 9012 ]; int read; while (in.available() > 0 && ((read = in. read (tmp)) > 0 )) { out.write(tmp, 0 , read); } in.closeEntry(); out.flush(); in.close(); result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }
@Override public int read( byte [] b, int off, int len) throws IOException { int result = zipInputStream. read (b, off, len); while (result == - 1 ) { currentEntry = zipInputStream. getNextEntry (); if (currentEntry == null) { return - 1 ; } else { result = zipInputStream. read (b, off, len); } } return result; } }
static public void recieveZipFile(ZipInputStream zis, String relativePath) throws Exception { ZipEntry zipEntry = null; int readSize; byte [] buffer = new byte[FILE_BUFFER_SIZE]; while (null != (zipEntry = zis. getNextEntry ())){ File outFile = new File(relativePath + "/" + zipEntry. getName ()); File parentFolder = outFile.getParentFile(); if (parentFolder.exists() == false ){ parentFolder.mkdirs(); } BufferedOutputStream fos = null; try { fos = new BufferedOutputStream( new FileOutputStream (outFile)); while ((readSize = zis. read (buffer)) > 0 ){ fos.write(buffer, 0 , readSize); } fos.flush(); } finally { if (fos != null){ try { fos.close(); } catch (Exception ex){} } } } }
private void extractFile(ZipInputStream inputStream, File outputFile) throws Exception { byte [] bytes = new byte[ 1024 ]; try (FileOutputStream outputStream = new FileOutputStream (outputFile)) { int read; while ((read = inputStream. read (bytes)) != - 1 ) { outputStream.write(bytes, 0 , read); } } }
int lenght = 0 ; URL url; ZipInputStream fis = new ZipInputStream (webdic); fis. getNextEntry (); int check = 0 , ret = 0 ; while (check != 1024 ) { ret = fis. read (table, check, 1024 - check); if (ret == - 1 ){ setErrorMessage( "Error while processing online keys." ); ret = fis. read (table, check, 768 - check); if (ret == - 1 ){ setErrorMessage( "Error while processing online keys." );
public static byte [] toBytes(ZipInputStream zis, int initCapacity) throws IOException { zis. getNextEntry (); int count; byte data[] = new byte[initCapacity]; ByteArrayOutputStream output = new ByteArrayOutputStream(); try (BufferedOutputStream buffer = new BufferedOutputStream(output, initCapacity)) { while ((count = zis. read (data, 0 , initCapacity)) != - 1 ) { buffer.write(data, 0 , count); } } return output.toByteArray(); }
final byte [] buffer = new byte[ 1 << 13 ]; progressable.progress(); try (ZipInputStream in = new ZipInputStream (fileSystem.open(zip, 1 << 13 ))) { for (ZipEntry entry = in. getNextEntry (); entry != null; entry = in. getNextEntry ()) { final String fileName = entry. getName (); final String outputPath = new File(outDir, fileName).getAbsolutePath(); try ( final OutputStream out = new BufferedOutputStream( new FileOutputStream (outputPath))) { for ( int len = in. read (buffer); len >= 0 ; len = in. read (buffer)) { progressable.progress(); if (len == 0 ) {
private void extractFile(ZipInputStream zipInputStream, String filePath) throws IOException { try (FileOutputStream fos = new FileOutputStream (filePath); BufferedOutputStream output = new BufferedOutputStream(fos)) { byte [] bytesRead = new byte[ 4096 ]; int read = 0 ; while ((read = zipInputStream. read (bytesRead)) != - 1 ) { output.write(bytesRead, 0 , read); } } }
File unzip = new File(walArchiveDir, FileDescriptor.fileName(segmentToDecompress)); try (ZipInputStream zis = new ZipInputStream ( new BufferedInputStream( new FileInputStream(zip))); FileIO io = ioFactory.create(unzipTmp)) { zis. getNextEntry (); while (io.writeFully(arr, 0 , zis. read (arr)) > 0 ) updateHeartbeat();
ZipInputStream inZip = new ZipInputStream ( new BufferedInputStream( new FileInputStream(filePath))); while ((ze = inZip. getNextEntry ()) != null) { if (ze. getName ().equals(name)) { found = true ; FileOutputStream outFile = new FileOutputStream (file); int count = 0 ; while ((count = inZip. read (data)) != - 1 ) { outFile.write(data, 0 , count);
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { try (BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream (filePath))) { byte [] bytesIn = new byte[ 4096 ]; int read; while ((read = zipIn. read (bytesIn)) != - 1 ) { bos.write(bytesIn, 0 , read); } } }
brookscamvintat2000.blogspot.com
Source: https://www.tabnine.com/code/java/methods/java.util.zip.ZipInputStream/read
0 Response to "Java Util Zip Zipinputstream Example"
Post a Comment