本文整理汇总了Java中java.util.zip.ZipEntry.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry.isDirectory方法的具体用法?Java ZipEntry.isDirectory怎么用?Java ZipEntry.isDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.isDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unzipEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
if (entry.isDirectory()) {
createDir(new File(outputDir, entry.getName()));
return;
}
File outputFile = new File(outputDir, entry.getName());
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
inputStream.close();
}
}
示例2: InMemoryZipFile
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public InMemoryZipFile(byte[] zipBuffer) throws IOException {
ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(zipBuffer));
while(true) {
ZipEntry entry;
do {
if((entry = zin.getNextEntry()) == null) {
zin.close();
return;
}
} while(entry.isDirectory());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] buf = new byte[10240];
int length;
while((length = zin.read(buf)) != -1) {
buffer.write(buf, 0, length);
}
zin.closeEntry();
this.contents.put(entry.getName(), buffer.toByteArray());
}
}
示例3: addFiles
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* @param pack The scriptFiles to set.
*/
private void addFiles(ZipFile pack)
{
for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
{
ZipEntry entry = e.nextElement();
if (entry.getName().endsWith(".xml"))
{
try
{
ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry));
_scriptFiles.add(newScript);
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
else if (!entry.isDirectory())
{
_otherFiles.add(entry.getName());
}
}
}
示例4: copyExistingFiles
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile) throws IOException {
// First, copy the contents from the existing outFile:
Enumeration<? extends ZipEntry> entries = inputFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = new ZipEntry(entries.nextElement());
// We can't reuse the compressed size because it depends on compression sizes.
entry.setCompressedSize(-1);
outputFile.putNextEntry(entry);
// No need to create directory entries in the final apk
if (! entry.isDirectory()) {
BrutIO.copy(inputFile, outputFile, entry);
}
outputFile.closeEntry();
}
}
示例5: getMimeTypeForEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private String getMimeTypeForEntry(ZipEntry entry) {
if (entry.isDirectory()) {
return Document.MIME_TYPE_DIR;
}
final int lastDot = entry.getName().lastIndexOf('.');
if (lastDot >= 0) {
final String extension = entry.getName().substring(lastDot + 1).toLowerCase(Locale.US);
final String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (mimeType != null) {
return mimeType;
}
}
return BASIC_MIME_TYPE;
}
示例6: readNonClasses
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Reads non-classes from the given jar.
*
* @param jarPath
* Path to jarfile to read non-classes from.
* @return Map of non-classes from the specified jarfile.
* @throws IOException
* If an exception was encountered while reading the jarfile.
*/
public static Map<String, byte[]> readNonClasses(String jarPath) throws IOException {
Map<String, byte[]> map = new HashMap<>();
try (ZipFile file = new ZipFile(jarPath)) {
Enumeration<? extends ZipEntry> entries = file.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.isDirectory() || entry.getName().contains(".class")) {
continue;
}
Recaf.INSTANCE.logging.fine("Reading jar resource: " + entry.getName(), 1);
try (InputStream is = file.getInputStream(entry)) {
map.put(entry.getName(), Streams.from(is));
}
}
}
return map;
}
示例7: unZipFile
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static void unZipFile(InputStream source, FileObject rootFolder) throws IOException {
try {
ZipInputStream str = new ZipInputStream(source);
ZipEntry entry;
while ((entry = str.getNextEntry()) != null) {
if (entry.isDirectory()) {
FileUtil.createFolder(rootFolder, entry.getName());
continue;
}
FileObject fo = FileUtil.createData(rootFolder, entry.getName());
FileLock lock = fo.lock();
try {
OutputStream out = fo.getOutputStream(lock);
try {
FileUtil.copy(str, out);
} finally {
out.close();
}
} finally {
lock.releaseLock();
}
}
} finally {
source.close();
}
}
示例8: getAttributes
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Retrieves all of the attributes associated with a named object.
*
* @return the set of attributes associated with name.
* Returns an empty attribute set if name has no attributes; never null.
* @param name the name of the object from which to retrieve attributes
* @exception NamingException if a naming exception is encountered
*/
@Override
public Attributes getAttributes(Name name, String[] attrIds)
throws NamingException {
Entry entry = null;
if (name.isEmpty())
entry = entries;
else
entry = treeLookup(name);
if (entry == null)
return null;
ZipEntry zipEntry = entry.getEntry();
ResourceAttributes attrs = new ResourceAttributes();
attrs.setCreationDate(new Date(zipEntry.getTime()));
attrs.setName(entry.getName());
if (!zipEntry.isDirectory())
attrs.setResourceType("");
else
attrs.setCollection(true);
attrs.setContentLength(zipEntry.getSize());
attrs.setLastModified(zipEntry.getTime());
return attrs;
}
示例9: uncompress
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static boolean uncompress(File zipFile) {
boolean success = false;
try {
FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
destFolder.mkdirs();
while ((entry = zis.getNextEntry()) != null) {
File dest = new File(destFolder, entry.getName());
dest.getParentFile().mkdirs();
if(entry.isDirectory()) {
if (!dest.exists()) {
dest.mkdirs();
}
} else {
int size;
byte[] buffer = new byte[2048];
FileOutputStream fos = new FileOutputStream(dest);
BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
IoUtils.flushQuietly(bos);
IoUtils.closeQuietly(bos);
}
zis.closeEntry();
}
IoUtils.closeQuietly(zis);
IoUtils.closeQuietly(fis);
success = true;
} catch (Exception e) {
e.printStackTrace();
}
return success;
}
示例10: unZip
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Given a File input it will unzip the file in a the unzip directory
* passed as the second parameter
* @param inFile The zip file as input
* @param unzipDir The unzip directory where to unzip the zip file.
* @throws IOException
*/
public static void unZip(File inFile, File unzipDir) throws IOException {
Enumeration<? extends ZipEntry> entries;
ZipFile zipFile = new ZipFile(inFile);
try {
entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
InputStream in = zipFile.getInputStream(entry);
try {
File file = new File(unzipDir, entry.getName());
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().isDirectory()) {
throw new IOException("Mkdirs failed to create " +
file.getParentFile().toString());
}
}
OutputStream out = new FileOutputStream(file);
try {
byte[] buffer = new byte[8192];
int i;
while ((i = in.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
}
} finally {
zipFile.close();
}
}
示例11: unzipEntry
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
public static void unzipEntry(
ZipInputStream zis,
ZipEntry entry,
byte[] buffer,
File outputDir)
throws IOException, RuntimeException
{
String entryName = entry.getName();
int pos = entryName.indexOf('/');
//for backward capability where the zip has root directory named "mapnik"
if (pos != ConstantsUI.NOT_FOUND) {
String folderName = entryName.substring(0, pos);
if (!TextUtils.isDigitsOnly(folderName)) {
entryName = entryName.substring(pos, entryName.length());
}
}
if (entry.isDirectory()) {
FileUtil.createDir(new File(outputDir, entryName));
return;
}
//for prevent searching by media library
entryName = entryName.replace(".png", ConstantsUI.TILE_EXT);
entryName = entryName.replace(".jpg", ConstantsUI.TILE_EXT);
entryName = entryName.replace(".jpeg", ConstantsUI.TILE_EXT);
if (entryName.toLowerCase().equals("mapnik.json"))
entryName = "config.json";
File outputFile = new File(outputDir, entryName);
if (!outputFile.getParentFile().exists()) {
FileUtil.createDir(outputFile.getParentFile());
}
FileOutputStream fout = new FileOutputStream(outputFile);
FileUtil.copyStream(zis, fout, buffer, ConstantsUI.IO_BUFFER_SIZE);
fout.close();
}
示例12: createMap
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
private static Map<String,List<String>> createMap(FileObject root, String pathIn) throws IOException {
final Map<String,List<String>> result = new HashMap<>();
try (ZipFile zf = new ZipFile(FileUtil.toFile(root))) {
final Enumeration<? extends ZipEntry> entries = zf.entries();
while (entries.hasMoreElements()) {
final ZipEntry e = entries.nextElement();
if (e.isDirectory()) {
continue;
}
String name = e.getName();
if (pathIn != null) {
if(!name.startsWith(pathIn)) {
continue;
} else {
name = name.substring(pathIn.length());
}
}
final String[] names = FileObjects.getFolderAndBaseName(name, '/'); //NOI18N
if (JavaFileObject.Kind.CLASS.equals(FileObjects.getKind(FileObjects.getExtension(names[1])))) {
List<String> c = result.get(names[0]);
if (c == null) {
result.put(names[0],c = new ArrayList<>());
}
c.add(names[1]);
}
}
}
return result;
}
示例13: extract
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Extracts content of Zip file to specified output path.
*
* @param is {@link InputStream} InputStream of Zip file
* @param outputFolder folder where Zip file should be extracted to
* @throws IOException
*/
public static void extract(InputStream is, File outputFolder) throws IOException {
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
byte[] buffer = new byte[1024];
while ((entry = zis.getNextEntry()) != null) {
File outputFile = new File(outputFolder.getCanonicalPath() + File.separatorChar + entry.getName());
File outputParent = new File(outputFile.getParent());
outputParent.mkdirs();
if (entry.isDirectory()) {
if (!outputFile.exists()) {
outputFile.mkdir();
}
} else {
FileOutputStream fos = new FileOutputStream(outputFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
}
}
示例14: getArchiveIterator
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
/**
* Iterates all entries in the given archive data that are nested under the relative location.
*
* @param archive
* the input stream with the zip entries. Will not be closed by this method, but has to be closed by the
* caller.
*/
protected Iterator<ZipEntry> getArchiveIterator(final ZipInputStream archive,
String archiveRelativeLocation) {
final String relativeLocation = archiveRelativeLocation + '/';
final Iterator<ZipEntry> iterator = new AbstractIterator<ZipEntry>() {
@Override
protected ZipEntry computeNext() {
try {
ZipEntry candidate = archive.getNextEntry();
while (candidate != null) {
if (!candidate.isDirectory()) {
String name = candidate.getName();
if (name.startsWith(relativeLocation)) {
return candidate;
}
}
candidate = archive.getNextEntry();
}
} catch (IOException e) {
// ignore
}
return endOfData();
}
};
return ImmutableList.copyOf(iterator).iterator();
}
示例15: ensureLoaded
import java.util.zip.ZipEntry; //导入方法依赖的package包/类
@Override
protected void ensureLoaded() throws RepositoryException {
if (folders != null && data != null) {
return;
}
this.folders = new LinkedList<Folder>();
this.data = new LinkedList<DataEntry>();
try (ZipInputStream zip = zipStream.getStream()) {
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
if (entry.isDirectory() || entry.getName().replaceFirst("/", "").contains("/")) {
continue;
}
if (zipStream.getStreamPath() != null && !entry.getName().startsWith(zipStream.getStreamPath())) {
continue;
}
String entryName = entry.getName();
if (entryName.endsWith(".ioo")) {
String ioObjectName = Paths.get(entryName).getFileName().toString().split("\\.")[0];
data.add(new ZipResourceIOObjectEntry(this, ioObjectName, getPath() + "/" + ioObjectName,
getRepository(), zipStream));
} else if (entryName.endsWith(".rmp")) {
String processName = Paths.get(entryName).getFileName().toString().split("\\.")[0];
data.add(new ZipResourceProcessEntry(this, processName, getPath() + "/" + processName, getRepository(),
zipStream));
} else if (entryName.endsWith(".blob")) {
String blobName = Paths.get(entryName).getFileName().toString().split("\\.")[0];
data.add(new ZipResourceBlobEntry(this, blobName, getPath() + "/" + blobName, getRepository(),
zipStream));
}
}
} catch (IOException e) {
throw new RepositoryException("Cannot load data from '" + getResource() + ": " + e, e);
}
}