本文整理了Java中java.util.zip.ZipOutputStream.flush()
方法的一些代码示例,展示了ZipOutputStream.flush()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipOutputStream.flush()
方法的具体详情如下:
包路径:java.util.zip.ZipOutputStream
类名称:ZipOutputStream
方法名:flush
暂无
代码示例来源:origin: scouter-project/scouter
public void closeEntry() throws IOException {
zos.flush();
zos.closeEntry();
}
}
代码示例来源:origin: Meituan-Dianping/Robust
protected void zipFile(byte[] classBytesArray, ZipOutputStream zos, String entryName) {
try {
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
zos.write(classBytesArray, 0, classBytesArray.length);
zos.closeEntry();
zos.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: pxb1988/dex2jar
public void dumpZip(Path exFile, String[] originalArgs) throws IOException {
try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(exFile))) {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos, StandardCharsets.UTF_8));
zos.putNextEntry(new ZipEntry("summary.txt"));
dumpTxt0(writer, originalArgs);
zos.closeEntry();
zos.flush();
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
@Override
public void write(OutputStream outStream) throws IOException {
ZipOutputStream zip = new ZipOutputStream(outStream);
for (File f : directory.listFiles()) {
zip.putNextEntry(new ZipEntry(f.getName()));
Files.copy(f, zip);
zip.closeEntry();
zip.flush();
}
zip.close();
}
}
代码示例来源:origin: Tencent/tinker
/**
* add zip entry
*
* @param zipOutputStream
* @param zipEntry
* @param inputStream
* @throws Exception
*/
public static void addZipEntry(ZipOutputStream zipOutputStream, ZipEntry zipEntry, InputStream inputStream) throws Exception {
try {
zipOutputStream.putNextEntry(zipEntry);
byte[] buffer = new byte[Constant.Capacity.BYTES_PER_KB];
int length = -1;
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
zipOutputStream.write(buffer, 0, length);
zipOutputStream.flush();
}
} catch (ZipException e) {
// do nothing
} finally {
StreamUtil.closeQuietly(inputStream);
zipOutputStream.closeEntry();
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
@Override
public void write(OutputStream outStream) throws IOException {
ZipOutputStream zip = new ZipOutputStream(outStream);
for (File f : directory.listFiles()) {
zip.putNextEntry(new ZipEntry(f.getName()));
Files.copy(f, zip);
zip.closeEntry();
zip.flush();
}
zip.close();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Override
public void close() throws IOException {
ZipOutputStream zos = (ZipOutputStream) delegate;
zos.flush();
zos.closeEntry();
zos.finish();
zos.close();
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static void zipFolder(String srcFolder, String destZipFile) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);
addFolderToZip("", srcFolder, zip);
zip.flush();
zip.close();
}
代码示例来源:origin: apache/incubator-druid
public static long zipAndCopyDir(
File baseDir,
OutputStream baseOutputStream,
Progressable progressable
) throws IOException
{
long size = 0L;
try (ZipOutputStream outputStream = new ZipOutputStream(baseOutputStream)) {
List<String> filesToCopy = Arrays.asList(baseDir.list());
for (String fileName : filesToCopy) {
final File fileToCopy = new File(baseDir, fileName);
if (java.nio.file.Files.isRegularFile(fileToCopy.toPath())) {
size += copyFileToZipStream(fileToCopy, outputStream, progressable);
} else {
log.warn("File at [%s] is not a regular file! skipping as part of zip", fileToCopy.getPath());
}
}
outputStream.flush();
}
return size;
}
代码示例来源:origin: Tencent/tinker
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath) throws IOException {
rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator) + resFile.getName();
if (resFile.isDirectory()) {
File[] fileList = resFile.listFiles();
for (File file : fileList) {
zipFile(file, zipout, rootpath);
}
} else {
final byte[] fileContents = readContents(resFile);
//linux format!!
if (rootpath.contains("\\")) {
rootpath = rootpath.replace("\\", "/");
}
ZipEntry entry = new ZipEntry(rootpath);
// if (compressMethod == ZipEntry.DEFLATED) {
entry.setMethod(ZipEntry.DEFLATED);
// } else {
// entry.setMethod(ZipEntry.STORED);
// entry.setSize(fileContents.length);
// final CRC32 checksumCalculator = new CRC32();
// checksumCalculator.update(fileContents);
// entry.setCrc(checksumCalculator.getValue());
// }
zipout.putNextEntry(entry);
zipout.write(fileContents);
zipout.flush();
zipout.closeEntry();
}
}
代码示例来源:origin: typ0520/fastdex
/**
* add zip entry
*
* @param zipOutputStream
* @param zipEntry
* @param inputStream
* @throws Exception
*/
public static void addZipEntry(ZipOutputStream zipOutputStream, ZipEntry zipEntry, InputStream inputStream) throws Exception {
try {
zipOutputStream.putNextEntry(zipEntry);
byte[] buffer = new byte[Constant.Capacity.BYTES_PER_KB];
int length = -1;
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
zipOutputStream.write(buffer, 0, length);
zipOutputStream.flush();
}
} catch (ZipException e) {
// do nothing
} finally {
if (inputStream != null) {
inputStream.close();
}
zipOutputStream.closeEntry();
}
}
代码示例来源:origin: gocd/gocd
public void done() throws IOException {
ZipOutputStream zip = null;
try {
zip = new ZipOutputStream(new BufferedOutputStream(destinationStream));
zip.setLevel(level);
for (Map.Entry<String, File> zipDirToSourceFileEntry : toAdd.entrySet()) {
File sourceFileToZip = zipDirToSourceFileEntry.getValue();
String destinationFolder = zipDirToSourceFileEntry.getKey();
zipUtil.addToZip(new ZipPath(destinationFolder), sourceFileToZip, zip, excludeRootDir);
}
zip.flush();
} finally {
if (zip != null) {
try {
zip.close();
} catch (IOException e) {
LOGGER.error("Failed to close the stream", e);
}
}
}
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
if (!(object instanceof ZIPCompressedMessage)) return;
ZIPCompressedMessage zipMessage = (ZIPCompressedMessage)object;
Message message = zipMessage.getMessage();
ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
Serializer.writeClassAndObject(tempBuffer, message);
ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
ZipOutputStream zipOutput = new ZipOutputStream(byteArrayOutput);
zipOutput.setLevel(zipMessage.getLevel());
ZipEntry zipEntry = new ZipEntry("zip");
zipOutput.putNextEntry(zipEntry);
tempBuffer.flip();
zipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
zipOutput.flush();
zipOutput.closeEntry();
zipOutput.close();
buffer.put(byteArrayOutput.toByteArray());
}
}
代码示例来源:origin: geoserver/geoserver
zipout.flush();
代码示例来源:origin: apache/incubator-druid
zipOut.flush();
zipOut.finish();
代码示例来源:origin: commonsguy/cw-omnibus
private File buildBackup() throws IOException {
File zipFile=new File(getCacheDir(), BACKUP_FILENAME);
if (zipFile.exists()) {
zipFile.delete();
}
FileOutputStream fos=new FileOutputStream(zipFile);
ZipOutputStream zos=new ZipOutputStream(fos);
zipDir(ZIP_PREFIX_FILES, getFilesDir(), zos);
zipDir(ZIP_PREFIX_PREFS, getSharedPrefsDir(this), zos);
zipDir(ZIP_PREFIX_EXTERNAL, getExternalFilesDir(null), zos);
zos.flush();
fos.getFD().sync();
zos.close();
return(zipFile);
}
代码示例来源:origin: zeroturnaround/zt-zip
private static void pack(ZipEntrySource[] entries, OutputStream os, boolean closeStream) {
try {
ZipOutputStream out = new ZipOutputStream(os);
for (int i = 0; i < entries.length; i++) {
addEntry(entries[i], out);
}
out.flush();
out.finish();
if (closeStream) {
out.close();
}
}
catch (IOException e) {
throw ZipExceptionUtil.rethrow(e);
}
}
代码示例来源:origin: looly/hutool
out.flush();
代码示例来源:origin: looly/hutool
out.flush();
代码示例来源:origin: apache/nifi
@Override
public void process(final OutputStream rawOut) throws IOException {
try (final OutputStream bufferedOut = new BufferedOutputStream(rawOut);
final ZipOutputStream out = new ZipOutputStream(bufferedOut)) {
out.setLevel(compressionLevel);
for (final FlowFile flowFile : contents) {
final String path = keepPath ? getPath(flowFile) : "";
final String entryName = path + flowFile.getAttribute(CoreAttributes.FILENAME.key());
final ZipEntry zipEntry = new ZipEntry(entryName);
zipEntry.setSize(flowFile.getSize());
try {
out.putNextEntry(zipEntry);
bin.getSession().exportTo(flowFile, out);
out.closeEntry();
unmerged.remove(flowFile);
} catch (ZipException e) {
getLogger().error("Encountered exception merging {}", new Object[] {flowFile}, e);
}
}
out.finish();
out.flush();
}
}
});
内容来源于网络,如有侵权,请联系作者删除!