本文整理汇总了Java中java.util.zip.ZipEntry.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.getTime方法的具体用法?Java ZipEntry.getTime怎么用?Java ZipEntry.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.getTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unpackZip
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName());
if (entry.isDirectory()) {
destination.mkdirs();
} else {
destination.getParentFile().mkdirs();
FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination));
}
if (entry.getTime() != -1) {
destination.setLastModified(entry.getTime());
}
}
}
示例2: 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());
}
}
}
示例3: ZipFile2
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public ZipFile2(String zipPath, ZipEntry entry) {
if (entry == null)
throw new IllegalArgumentException("file must not be null");
if(!zipPath.endsWith("/"))
zipPath += "/";
mPath = zipPath+entry.getName();
mLength = entry.getSize();
mIsFile = !entry.isDirectory();
mLastModified = entry.getTime();
}
示例4: unzip
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* @source http://stackoverflow.com/a/27050680
*/
public static void unzip(InputStream zipFile, File targetDirectory) throws Exception {
ZipInputStream in = new ZipInputStream(new BufferedInputStream(zipFile));
try {
ZipEntry ze;
int count;
byte[] buffer = new byte[8192];
while ((ze = in.getNextEntry()) != null) {
File file = new File(targetDirectory, ze.getName());
File dir = ze.isDirectory() ? file : file.getParentFile();
if (!dir.isDirectory() && !dir.mkdirs()) {
throw new Exception("Failed to ensure directory: " + dir.getAbsolutePath());
}
if (ze.isDirectory()) {
continue;
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
try {
while ((count = in.read(buffer)) != -1)
out.write(buffer, 0, count);
} finally {
out.close();
}
long time = ze.getTime();
if (time > 0) {
file.setLastModified(time);
}
}
} finally {
in.close();
}
}
示例5: zeString
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
static String zeString(ZipEntry ze) {
int store = (ze.getCompressedSize() > 0) ?
(int)( (1.0 - ((double)ze.getCompressedSize()/(double)ze.getSize()))*100 )
: 0 ;
// Follow unzip -lv output
return ze.getSize() + "\t" + ze.getMethod()
+ "\t" + ze.getCompressedSize() + "\t"
+ store + "%\t"
+ new Date(ze.getTime()) + "\t"
+ Long.toHexString(ze.getCrc()) + "\t"
+ ze.getName() ;
}
示例6: getBuildDateAsString
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* INTERNAL method that returns the build date of the current APK as a string, or null if unable to determine it.
*
* @param context A valid context. Must not be null.
* @param dateFormat DateFormat to use to convert from Date to String
* @return The formatted date, or "Unknown" if unable to determine it.
*/
private static String getBuildDateAsString(Context context, DateFormat dateFormat) {
String buildDate;
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
ZipFile zf = new ZipFile(ai.sourceDir);
ZipEntry ze = zf.getEntry("classes.dex");
long time = ze.getTime();
buildDate = dateFormat.format(new Date(time));
zf.close();
} catch (Exception e) {
buildDate = "Unknown";
}
return buildDate;
}
示例7: getAllJarConfigs
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private List<ConfigFile> getAllJarConfigs(final String[] suffixes) throws IOException {
List<ConfigFile> configs = new ArrayList<>();
String metaPath = "META-INF";
Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(metaPath);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (url != null && "jar".equals(url.getProtocol())) {
String urlStr = url.toString();
String location = urlStr.substring(urlStr.indexOf('f'), urlStr.lastIndexOf('!'));
String jarName = location.substring(location.lastIndexOf('/')+1, location.length());
URL realUrl = new URL(location);
try (ZipInputStream zip = new ZipInputStream(realUrl.openStream())) {
ZipEntry ze;
while ((ze = zip.getNextEntry()) != null) {
boolean canAdd = false;
String zeNameLowerCase = ze.getName().toLowerCase();
/*
if(zeNameLowerCase.endsWith("pom.xml") || zeNameLowerCase.endsWith("pom.properties")){
continue;
}*/
for (String suf : suffixes) {
if(zeNameLowerCase.endsWith("." + suf)) {
canAdd = true;
break;
}
}
if(canAdd) {
ConfigFile configFile = new ConfigFile();
configFile.lastModified = ze.getTime();
configFile.size = ze.getSize();
configFile.name = jarName + "!/" + ze.getName();
configFile.path = location + "!/" + ze.getName();
configs.add(configFile);
}
}
} catch (Throwable e) {
logger.warn("get jar maven pom failed! location:" + location, e);
}
}
}
return configs;
}