gpt4 book ai didi

java.util.zip.ZipInputStream.read()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 00:44:40 28 4
gpt4 key购买 nike

本文整理了Java中java.util.zip.ZipInputStream.read()方法的一些代码示例,展示了ZipInputStream.read()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipInputStream.read()方法的具体详情如下:
包路径:java.util.zip.ZipInputStream
类名称:ZipInputStream
方法名:read

ZipInputStream.read介绍

[英]Reads up to byteCount uncompressed bytes into the buffer starting at byteOffset. Returns the number of bytes actually read, or -1.
[中]从字节偏移量开始,最多可将字节数未压缩字节读入缓冲区。返回实际读取的字节数,或-1。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

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);
  }
 }
}

代码示例来源:origin: apache/ignite

/**
 * Unzip bytes.
 *
 * @param input Zipped bytes.
 * @return Unzipped byte array.
 * @throws IOException
 */
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();
}
/** {@inheritDoc} */

代码示例来源:origin: syncany/syncany

@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);
}

代码示例来源:origin: geoserver/geoserver

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();
  }
}

代码示例来源:origin: apache/incubator-atlas

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();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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;
}

代码示例来源:origin: de.adorsys.smartanalytics/smartanalytics-core

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());
  }
}

代码示例来源:origin: scouter-project/scouter

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){}
      }
    }
  }
}

代码示例来源:origin: org.geowebcache/gwc-sqlite

private void extractFile(ZipInputStream inputStream, File outputFile) throws Exception {
  // extracting zip entry file content
  byte[] bytes = new byte[1024];
  try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
    int read;
    while ((read = inputStream.read(bytes)) != -1) {
      outputStream.write(bytes, 0, read);
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@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());
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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;
 }
}

代码示例来源:origin: scouter-project/scouter

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){}
      }
    }
  }
}

代码示例来源:origin: GeoWebCache/geowebcache

private void extractFile(ZipInputStream inputStream, File outputFile) throws Exception {
  // extracting zip entry file content
  byte[] bytes = new byte[1024];
  try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
    int read;
    while ((read = inputStream.read(bytes)) != -1) {
      outputStream.write(bytes, 0, read);
    }
  }
}

代码示例来源:origin: cSploit/android

int lenght = 0;
URL url;
ZipInputStream fis = new ZipInputStream(webdic);
fis.getNextEntry();
int check = 0, ret = 0;
while(check != 1024)/* ZipInputStream doens't seems to block. */{
 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.");

代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common

public static byte[] toBytes(ZipInputStream zis, int initCapacity) throws IOException {
 // advance to the next entry
 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();
}

代码示例来源:origin: apache/incubator-druid

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) {

代码示例来源:origin: apache/incubator-slider

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);
  }
 }
}

代码示例来源:origin: apache/ignite

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();

代码示例来源:origin: TeamNewPipe/NewPipe

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);

代码示例来源:origin: org.wso2.appserver/sso-quickstart

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);
    }
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com