本文整理汇总了Java中java.util.zip.ZipEntry.setTime方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.setTime方法的具体用法?Java ZipEntry.setTime怎么用?Java ZipEntry.setTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.setTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFile
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Create a new entry in the zip file with the given content.
*/
public void writeFile(InputStream contentStream, long timeStamp, String destinationPath) throws IOException {
ZipEntry newEntry = new ZipEntry(destinationPath);
byte[] readBuffer = new byte[4096];
newEntry.setTime(timeStamp);
outputStream.putNextEntry(newEntry);
try {
int n;
while ((n = contentStream.read(readBuffer)) > 0) {
outputStream.write(readBuffer, 0, n);
}
} finally {
if (contentStream != null) {
contentStream.close();
}
}
outputStream.closeEntry();
}
示例2: writeEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze)
throws IOException {
ZipEntry ze2 = new ZipEntry(ze.getName());
ze2.setMethod(ze.getMethod());
ze2.setTime(ze.getTime());
ze2.setComment(ze.getComment());
ze2.setExtra(ze.getExtra());
if (ze.getMethod() == ZipEntry.STORED) {
ze2.setSize(ze.getSize());
ze2.setCrc(ze.getCrc());
}
os.putNextEntry(ze2);
writeBytes(zf, ze, os);
}
示例3: copyStreamToJar
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void copyStreamToJar(InputStream zin,
ZipOutputStream out,
String currentName,
long fileTime,
ZipEntry zipEntry) throws IOException {
// Create new entry for zip file.
ZipEntry newEntry = new ZipEntry(currentName);
// Make sure there is date and time set.
if (fileTime != -1) {
newEntry.setTime(fileTime); // If found set it into output file.
}
out.putNextEntry(newEntry);
if (zin != null) {
IOUtils.copy(zin, out);
}
}
示例4: testTimeConversions
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static void testTimeConversions(long from, long to, long step) {
ZipEntry ze = new ZipEntry("TestExtraTime.java");
for (long time = from; time <= to; time += step) {
ze.setTime(time);
FileTime lastModifiedTime = ze.getLastModifiedTime();
if (lastModifiedTime.toMillis() != time) {
throw new RuntimeException("setTime should make getLastModifiedTime " +
"return the specified instant: " + time +
" got: " + lastModifiedTime.toMillis());
}
if (ze.getTime() != time) {
throw new RuntimeException("getTime after setTime, expected: " +
time + " got: " + ze.getTime());
}
}
}
示例5: cloneEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private ZipEntry cloneEntry(ZipEntry entry) {
ZipEntry newEntry = new ZipEntry(entry.getName());
newEntry.setTime(entry.getTime());
if (entry.getCreationTime() != null) {
newEntry.setCreationTime(entry.getCreationTime());
}
if (entry.getLastModifiedTime() != null) {
newEntry.setLastModifiedTime(entry.getLastModifiedTime());
}
if (entry.getLastAccessTime() != null) {
newEntry.setLastAccessTime(entry.getLastAccessTime());
}
newEntry.setComment(entry.getComment());
newEntry.setExtra(entry.getExtra());
return newEntry;
}
示例6: zipDirectoryInternal
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Private helper function for zipping files. This one goes recursively
* through the input directory and all of its subdirectories and adds the
* single zip entries.
*
* @param inputFile the file or directory to be added to the zip file
* @param directoryName the string-representation of the parent directory
* name. Might be an empty name, or a name containing multiple directory
* names separated by "/". The directory name must be a valid name
* according to the file system limitations. The directory name should be
* empty or should end in "/".
* @param zos the zipstream to write to
* @throws IOException the zipping failed, e.g. because the output was not
* writeable.
*/
private static void zipDirectoryInternal(
File inputFile,
String directoryName,
ZipOutputStream zos) throws IOException {
String entryName = directoryName + inputFile.getName();
if (inputFile.isDirectory()) {
entryName += "/";
// We are hitting a sub-directory. Recursively add children to zip in deterministic,
// sorted order.
File[] childFiles = inputFile.listFiles();
if (childFiles.length > 0) {
Arrays.sort(childFiles);
// loop through the directory content, and zip the files
for (File file : childFiles) {
zipDirectoryInternal(file, entryName, zos);
}
// Since this directory has children, exit now without creating a zipentry specific to
// this directory. The entry for a non-entry directory is incompatible with certain
// implementations of unzip.
return;
}
}
// Put the zip-entry for this file or empty directory into the zipoutputstream.
ZipEntry entry = new ZipEntry(entryName);
entry.setTime(inputFile.lastModified());
zos.putNextEntry(entry);
// Copy file contents into zipoutput stream.
if (inputFile.isFile()) {
Files.asByteSource(inputFile).copyTo(zos);
}
}
示例7: writeEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void writeEntry(String name, Set<String> written, ZipOutputStream zos, File f) throws IOException, FileNotFoundException {
if (!written.add(name)) {
return;
}
int idx = name.lastIndexOf('/', name.length() - 2);
if (idx != -1) {
writeEntry(name.substring(0, idx + 1), written, zos, f.getParentFile());
}
ZipEntry ze = new ZipEntry(name);
ze.setTime(f.lastModified());
if (name.endsWith("/")) {
ze.setMethod(ZipEntry.STORED);
ze.setSize(0);
ze.setCrc(0);
zos.putNextEntry(ze);
} else {
InputStream is = new FileInputStream(f);
ze.setMethod(ZipEntry.DEFLATED);
ze.setSize(f.length());
CRC32 crc = new CRC32();
try {
copyStreams(is, null, crc);
} finally {
is.close();
}
ze.setCrc(crc.getValue());
zos.putNextEntry(ze);
InputStream zis = new FileInputStream(f);
try {
copyStreams(zis, zos, null);
} finally {
zis.close();
}
}
}
示例8: process
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile) throws Throwable {
ZipFile zipFile = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
try {
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
try (InputStream in = zipFile.getInputStream(entry)) {
ClassReader cr = new ClassReader(in);
ClassNode classNode = new ClassNode();
cr.accept(classNode, 0);
removeAttr(classNode);
ClassWriter cw = new ClassWriter(0);
classNode.accept(cw);
ZipEntry newEntry = new ZipEntry(entry.getName());
newEntry.setTime(System.currentTimeMillis());
out.putNextEntry(newEntry);
writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
}
} else {
entry.setTime(System.currentTimeMillis());
out.putNextEntry(entry);
writeToFile(out, zipFile.getInputStream(entry));
}
}
} finally {
zipFile.close();
out.close();
}
}
示例9: compressFile
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static boolean compressFile(File toCompress, File target) {
if (target == null || toCompress == null) {
return false;
}
try {
final Uri uri = Uri.fromFile(toCompress);
final String rootPath = Utils.getParentUrl(uri.toString());
final int rootOffset = rootPath.length();
ZipOutputStream zos = new ZipOutputStream(FileEditorFactory.getFileEditorForUrl(Uri.fromFile(target), null).getOutputStream());
ZipEntry entry = new ZipEntry(uri.toString().substring(rootOffset));
byte[] bytes = new byte[1024];
InputStream fis = FileEditorFactory.getFileEditorForUrl(uri, null).getInputStream();
entry.setSize(toCompress.length());
entry.setTime(toCompress.lastModified());
zos.putNextEntry(entry);
int count;
while ((count = fis.read(bytes)) > 0) {
zos.write(bytes, 0, count);
}
zos.closeEntry();
closeSilently(fis);
closeSilently(zos);
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例10: process
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile, String message) throws Throwable {
ZipFile zipFile = new ZipFile(jarFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
try {
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
try (InputStream in = zipFile.getInputStream(entry)) {
ClassReader cr = new ClassReader(in);
ClassNode classNode = new ClassNode();
cr.accept(classNode, 0);
messageInjector(classNode, message);
ClassWriter cw = new ClassWriter(0);
classNode.accept(cw);
ZipEntry newEntry = new ZipEntry(entry.getName());
newEntry.setTime(System.currentTimeMillis());
out.putNextEntry(newEntry);
writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
}
} else {
entry.setTime(System.currentTimeMillis());
out.putNextEntry(entry);
writeToFile(out, zipFile.getInputStream(entry));
}
}
} finally {
zipFile.close();
out.close();
if (!messagegotinjected) {
// throw new IllegalStateException("Could not find Bukkit onEnable or onLoad method.");
throw new IllegalStateException("Could not find Bukkit onEnable method.");
}
}
}
示例11: getEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
public ZipEntry getEntry() {
ZipEntry zipEntry = new ZipEntry(path);
if (!file.isDirectory()) {
zipEntry.setSize(file.length());
}
zipEntry.setTime(0L);
return zipEntry;
}
示例12: extract
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo, String extractedFilePrefix) throws IOException, FileNotFoundException {
Throwable th;
InputStream in = apk.getInputStream(dexFile);
File tmp = File.createTempFile(extractedFilePrefix, EXTRACTED_SUFFIX, extractTo.getParentFile());
Log.i(TAG, "Extracting " + tmp.getPath());
try {
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
try {
ZipEntry classesDex = new ZipEntry("classes.dex");
classesDex.setTime(dexFile.getTime());
out.putNextEntry(classesDex);
byte[] buffer = new byte[16384];
for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
out.write(buffer, 0, length);
}
out.closeEntry();
out.close();
Log.i(TAG, "Renaming to " + extractTo.getPath());
if (tmp.renameTo(extractTo)) {
closeQuietly(in);
tmp.delete();
return;
}
throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() + "\" to \"" + extractTo.getAbsolutePath() + "\"");
} catch (Throwable th2) {
th = th2;
ZipOutputStream zipOutputStream = out;
closeQuietly(in);
tmp.delete();
throw th;
}
} catch (Throwable th3) {
th = th3;
closeQuietly(in);
tmp.delete();
throw th;
}
}
示例13: zipLog
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void zipLog(ZipOutputStream zos, File file) throws IOException {
ZipEntry zipEntry = new ZipEntry(file.getName());
zipEntry.setTime(file.lastModified());
zos.putNextEntry(zipEntry);
try (
InputStream is = new FileInputStream(file)
) {
int length;
byte[] buffer = new byte[0x1000];
while ((length = is.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
}
zos.closeEntry();
}
示例14: extract
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo, String extractedFilePrefix) throws IOException, FileNotFoundException {
Throwable th;
InputStream in = apk.getInputStream(dexFile);
File tmp = File.createTempFile(extractedFilePrefix, EXTRACTED_SUFFIX, extractTo.getParentFile());
Log.i(TAG, "Extracting " + tmp.getPath());
try {
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
try {
ZipEntry classesDex = new ZipEntry("classes.dex");
classesDex.setTime(dexFile.getTime());
out.putNextEntry(classesDex);
byte[] buffer = new byte[16384];
for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
out.write(buffer, 0, length);
}
out.closeEntry();
out.close();
Log.i(TAG, "Renaming to " + extractTo.getPath());
if (tmp.renameTo(extractTo)) {
closeQuietly(in);
tmp.delete();
return;
}
throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() + "\" to \"" + extractTo.getAbsolutePath() + a.e);
} catch (Throwable th2) {
th = th2;
ZipOutputStream zipOutputStream = out;
closeQuietly(in);
tmp.delete();
throw th;
}
} catch (Throwable th3) {
th = th3;
closeQuietly(in);
tmp.delete();
throw th;
}
}
示例15: readEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static ZipEntry readEntry(ByteBuffer in) throws IOException {
int sig = in.getInt();
if (sig != CENSIG) {
throw new ZipException("Central Directory Entry not found");
}
in.position(8);
int gpbf = in.getShort() & 0xffff;
if ((gpbf & GPBF_UNSUPPORTED_MASK) != 0) {
throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
}
int compressionMethod = in.getShort() & 0xffff;
int time = in.getShort() & 0xffff;
int modDate = in.getShort() & 0xffff;
// These are 32-bit values in the file, but 64-bit fields in this object.
long crc = ((long) in.getInt()) & 0xffffffffL;
long compressedSize = ((long) in.getInt()) & 0xffffffffL;
long size = ((long) in.getInt()) & 0xffffffffL;
int nameLength = in.getShort() & 0xffff;
int extraLength = in.getShort() & 0xffff;
int commentByteCount = in.getShort() & 0xffff;
// This is a 32-bit value in the file, but a 64-bit field in this object.
in.position(42);
long localHeaderRelOffset = ((long) in.getInt()) & 0xffffffffL;
byte[] nameBytes = new byte[nameLength];
in.get(nameBytes, 0, nameBytes.length);
String name = new String(nameBytes, 0, nameBytes.length, UTF_8);
ZipEntry entry = new ZipEntry(name);
entry.setMethod(compressionMethod);
entry.setTime(getTime(time, modDate));
entry.setCrc(crc);
entry.setCompressedSize(compressedSize);
entry.setSize(size);
// The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
// actually IBM-437.)
if (commentByteCount > 0) {
byte[] commentBytes = new byte[commentByteCount];
in.get(commentBytes, 0, commentByteCount);
entry.setComment(new String(commentBytes, 0, commentBytes.length, UTF_8));
}
if (extraLength > 0) {
byte[] extra = new byte[extraLength];
in.get(extra, 0, extraLength);
entry.setExtra(extra);
}
return entry;
}