gpt4 book ai didi

org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.write()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 20:28:40 27 4
gpt4 key购买 nike

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

ZipArchiveOutputStream.write介绍

[英]Writes bytes to ZIP entry.
[中]将字节写入ZIP条目。

代码示例

代码示例来源:origin: org.apache.commons/commons-compress

private void preClose() throws IOException {
  if (finished) {
    throw new IOException("Stream has already been finished");
  }
  if (entry == null) {
    throw new IOException("No current entry to close");
  }
  if (!entry.hasWritten) {
    write(EMPTY, 0, 0);
  }
}

代码示例来源:origin: plutext/docx4j

part.getPartName().getName().substring(1) );
if (bytes == null) throw new IOException("part '" + part.getPartName() + "' not found");
zos.write( bytes.getBytes() );
  zos.write(bytes, 0, read);

代码示例来源:origin: plutext/docx4j

zos.write( bytes );

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

private static void zipStoreBuffer(ZipArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException {
  ZipEntry zipEntry = new ZipEntry(name != null ? name : UUID.randomUUID().toString());
  zipEntry.setMethod(ZipOutputStream.STORED);
  zipEntry.setSize(dataBuffer.length);
  CRC32 crc32 = new CRC32();
  crc32.update(dataBuffer);
  zipEntry.setCrc(crc32.getValue());
  try {
    zip.putArchiveEntry(new ZipArchiveEntry(zipEntry));
  } catch (ZipException ex) {
    if (name != null) {
      zipStoreBuffer(zip, "x-" + name, dataBuffer);
      return;
    }
  }
  zip.write(dataBuffer);
  zip.closeArchiveEntry();
}

代码示例来源:origin: naver/ngrinder

fis = new FileInputStream(f);
while ((length = fis.read(buf, 0, buf.length)) >= 0) {
  zos.write(buf, 0, length);

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

private void preClose() throws IOException {
  if (finished) {
    throw new IOException("Stream has already been finished");
  }
  if (entry == null) {
    throw new IOException("No current entry to close");
  }
  if (!entry.hasWritten) {
    write(EMPTY, 0, 0);
  }
}

代码示例来源:origin: USPTO/PatentPublicData

@Override
public void write(byte[] bytes) throws IOException {
  Preconditions.checkState(isOpen(), "ZipArchive is not open!");
  outputZip.write(bytes);
  outputZip.flush();
}

代码示例来源:origin: org.apache.wookie/wookie-parser

/**
   * Recursively locates and adds files and folders to a zip archive
   * @param file
   * @param out
   * @param path
   * @throws IOException
   */
  private static void pack(File file, ZipArchiveOutputStream out, String path) throws IOException {
    if(file.isDirectory()){
      path = path + file.getName() +"/";
      for(File afile: file.listFiles()){
        pack(afile,out, path);
      }
    } else {
      ZipArchiveEntry entry = (ZipArchiveEntry) out.createArchiveEntry(file, path + file.getName());
      out.putArchiveEntry(entry);
      byte[] buf = new byte[1024];
      int len;
      FileInputStream in = new FileInputStream(file);
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
       }
      out.closeArchiveEntry();
    }
  }
}

代码示例来源:origin: stackoverflow.com

byte[] zip(byte[] data, String filename) {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos);
   ZipArchiveEntry entry = new ZipArchiveEntry(filename);
   entry.setSize(data.length);
   zos.putArchiveEntry(entry);
   zos.write(data);
   zos.closeArchiveEntry();
   zos.close();
   bos.close();
   return bos.toByteArray();       
 }

代码示例来源:origin: com.haulmont.reports/reports-core

protected byte[] zipContent(Map<String, Object> stringObjectMap) throws IOException {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
  zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
  zipOutputStream.setEncoding(ENCODING);
  for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
    byte[] data = (byte[]) entry.getValue();
    ArchiveEntry archiveEntry = newStoredEntry(entry.getKey(), data);
    zipOutputStream.putArchiveEntry(archiveEntry);
    zipOutputStream.write(data);
    zipOutputStream.closeArchiveEntry();
  }
  zipOutputStream.close();
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

@Override
public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) {
  String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
  byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
  zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
  zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
  ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes);
  try {
    zipOutputStream.putArchiveEntry(singleDesignEntry);
    zipOutputStream.write(jsonBytes);
    zipOutputStream.closeArchiveEntry();
  } catch (Exception e) {
    throw new RuntimeException("Error on creating zip archive during entities export", e);
  } finally {
    IOUtils.closeQuietly(zipOutputStream);
  }
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

@Override
public byte[] exportFolder(Folder folder) throws IOException {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
  zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
  zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
  String xml = createXStream().toXML(folder);
  byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
  ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
  zipOutputStream.putArchiveEntry(zipEntryDesign);
  zipOutputStream.write(xmlBytes);
  try {
    zipOutputStream.closeArchiveEntry();
  } catch (Exception ex) {
    throw new RuntimeException(String.format("Exception occurred while exporting folder %s.",  folder.getName()));
  }
  zipOutputStream.close();
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
  if (!logFile.exists()) {
    throw new FileNotFoundException();
  }
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
  zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
  zipOutputStream.setEncoding(ZIP_ENCODING);
  byte[] content = getTailBytes(logFile);
  ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
  zipOutputStream.putArchiveEntry(archiveEntry);
  zipOutputStream.write(content);
  zipOutputStream.closeArchiveEntry();
  zipOutputStream.close();
}

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

zipEntry.setUnixMode(UnixStat.LINK_FLAG | UnixStat.DEFAULT_FILE_PERM);
  tOut.putArchiveEntry(zipEntry);
  tOut.write(Files.readSymbolicLink(f).toString().getBytes());
  tOut.closeArchiveEntry();
}  else {

代码示例来源:origin: org.apache.karaf.tooling/karaf-maven-plugin

zipEntry.setUnixMode(UnixStat.LINK_FLAG | UnixStat.DEFAULT_FILE_PERM);
  tOut.putArchiveEntry(zipEntry);
  tOut.write(Files.readSymbolicLink(f).toString().getBytes());
  tOut.closeArchiveEntry();
}  else {

代码示例来源:origin: stackoverflow.com

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import java.util.Arrays;

public class Test {

public static void main(String[] args) throws Exception {
   ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(System.out);
   byte[] data = new byte[1024*1024];
   for(byte i=49; i<120; i++) {
     Arrays.fill(data, i);
     ArchiveEntry file1 = new ZipArchiveEntry("file" + i + ".txt");
     zipOut.putArchiveEntry(file1);
     zipOut.write(data);
     zipOut.closeArchiveEntry();
    }
    zipOut.finish();
    zipOut.close();
  }
}

代码示例来源:origin: com.haulmont.reports/reports-core

zipOutputStream.write(reportDocument.getContent());

代码示例来源:origin: com.haulmont.reports/reports-core

@Override
public byte[] exportReports(Collection<Report> reports) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
  try {
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(ENCODING);
    for (Report report : reports) {
      try {
        byte[] reportBytes = exportReport(report);
        ArchiveEntry singleReportEntry = newStoredEntry(replaceForbiddenCharacters(report.getName()) + ".zip", reportBytes);
        zipOutputStream.putArchiveEntry(singleReportEntry);
        zipOutputStream.write(reportBytes);
        zipOutputStream.closeArchiveEntry();
      } catch (IOException e) {
        throw new ReportingException(String.format("Exception occurred while exporting report [%s]", report.getName()), e);
      }
    }
  } finally {
    IOUtils.closeQuietly(zipOutputStream);
  }
  return byteArrayOutputStream.toByteArray();
}

代码示例来源:origin: com.haulmont.reports/reports-core

ArchiveEntry zipEntryReportObject = newStoredEntry("report.structure", xmlBytes);
zipOutputStream.putArchiveEntry(zipEntryReportObject);
zipOutputStream.write(xmlBytes);
          "templates/" + i + "/" + template.getName(), fileBytes);
      zipOutputStream.putArchiveEntry(zipEntryTemplate);
      zipOutputStream.write(fileBytes);

代码示例来源:origin: org.docx4j/docx4j

zos.write( bytes );

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