本文整理汇总了Java中org.apache.tools.zip.ZipEntry类的典型用法代码示例。如果您正苦于以下问题:Java ZipEntry类的具体用法?Java ZipEntry怎么用?Java ZipEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZipEntry类属于org.apache.tools.zip包,在下文中一共展示了ZipEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
public void writeTo(OutputStream out) throws IOException {
final Set<String> filenames = new HashSet<String>();
final ZipOutputStream zipout = new ZipOutputStream(out);
for (IFile f : container.getFiles()) {
assertNoAbsolutePath(f);
assertNoDuplicates(filenames, f);
ZipEntry entry = new ZipEntry(f.getLocalPath());
entry.setTime(f.getLastModified());
if (f.getPermissions() != IFile.UNDEF_PERMISSIONS) {
entry.setUnixMode(f.getPermissions());
}
zipout.putNextEntry(entry);
f.writeTo(zipout);
zipout.closeEntry();
}
zipout.finish();
}
示例2: getZipEntriesByPath
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
* パス表現で指定したディレクトリのZipEntryのリストを取得する.
* <p>
* expressionで指定した正規表現に対応するエントリーを取得する.
* (前方一致)
* </p>
* <h3>例:expressionに"temp/dataA/xyz"を指定した場合</h3>
* <ul>
* <li>temp/dataA/xyzディレクトリ及びその下の階層は含まれる.
* <li>temp/dataA/xyzzzディレクトリ及びその下の階層は含まれる.
* <li>temp/dataA/xyzがファイルであればそのファイルが唯一含まれる.
* <li>
* </ul>
* @param expression パス表現. nullの場合はすべてを対象とする.
* @return 取得したList. 該当が1件も無い場合は空のリストを返す.
*/
@SuppressWarnings("rawtypes")
public List<ZipEntry> getZipEntriesByPath(String expression) {
List<ZipEntry> resultList = new ArrayList<ZipEntry>();
Enumeration entryEnum = this.zipFile.getEntries();
while (entryEnum.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entryEnum.nextElement();
if (null != expression) {
if (0 > entry.getName().indexOf(expression)) {
// 取得対象に含まない場合はリストへの追加をスキップする.
continue;
}
}
// 日本語ファイル名を変換する.
resultList.add(entry);
}
return resultList;
}
示例3: getRootDirectory
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
* ルートディレクトリ名を取得する.
* @return ルートディレクトリ名.
*/
public String getRootDirectory() {
String result = null;
// 直下のファイルがあればルート無しとする。
List<ZipEntry> list = getZipEntriesByPath();
for (ZipEntry entry : list) {
int pos = entry.getName().indexOf('/');
if (-1 == pos) {
result = "";
break;
} else {
String rootName = entry.getName().substring(0, pos);
if (null == result) {
result = rootName;
} else {
if (!result.equals(rootName)) {
// 最上位に異なるディレクトリが見つかったということは親無し
result = "";
break;
}
}
}
}
return result;
}
示例4: isFileConflict
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private boolean isFileConflict(File file) throws IOException{
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name;
String filename;
File outFile;
boolean fileConflict=false;
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
name = entry.getName();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
outFile = new File(realPathResolver.get(filename));
if(outFile.exists()){
fileConflict=true;
break;
}
}
}
zip.close();
return fileConflict;
}
示例5: getPlugPerms
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private String getPlugPerms(File file) throws IOException{
ZipFile zip = new ZipFile(file, "GBK");
ZipEntry entry;
String name,filename;
File propertyFile;
String plugPerms="";
Enumeration<ZipEntry> en = zip.getEntries();
while (en.hasMoreElements()) {
entry = en.nextElement();
name = entry.getName();
if (!entry.isDirectory()) {
name = entry.getName();
filename = name;
//读取属性文件的plug.mark属性
if(filename.startsWith(PLUG_FILE_PREFIX)&&filename.endsWith(".properties")){
propertyFile = new File(realPathResolver.get(filename));
Properties p=new Properties();
p.load(new FileInputStream(propertyFile));
plugPerms=p.getProperty(PLUG_PERMS);
}
}
}
zip.close();
return plugPerms;
}
示例6: createZipOutputStream
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
public void createZipOutputStream() throws Exception {
final String FILE_NAME = "custom/output/zipOutputStream.zip";
//
ZipOutputStream value = IoHelper.createZipOutputStream(FILE_NAME);
System.out.println(value);
assertNotNull(value);
//
String fileName = "custom/output/test.log";
byte[] contents = IoHelper.read(fileName);
ZipEntry zipEntry = new ZipEntry(fileName);
value.putNextEntry(zipEntry);
value.write(contents);
// 須加 close,強制寫入
IoHelper.close(value);
}
示例7: zip
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
public static void zip(String path, List<File> files) throws IOException {
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(
new FileOutputStream(path), 1024));
for(File f : files) {
String zipName = f.getName();
if(!f.getName().contains(".png")) {
zipName = f.getName() + ".xml";
}
ZipEntry ze = new ZipEntry(zipName);
ze.setTime(f.lastModified());
DataInputStream dis = new DataInputStream(new BufferedInputStream(
new FileInputStream(f)));
zos.putNextEntry(ze);
int c;
while ((c = dis.read()) != -1) {
zos.write(c);
}
}
zos.setEncoding("gbk");
zos.closeEntry();
zos.close();
}
示例8: getInputStream
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
* Return an InputStream for reading the contents of this Resource.
* @return an InputStream object.
* @throws IOException if the zip file cannot be opened,
* or the entry cannot be read.
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
return ((Resource) getCheckedRef()).getInputStream();
}
final ZipFile z = new ZipFile(getZipfile(), getEncoding());
ZipEntry ze = z.getEntry(getName());
if (ze == null) {
z.close();
throw new BuildException("no entry " + getName() + " in "
+ getArchive());
}
return new FilterInputStream(z.getInputStream(ze)) {
public void close() throws IOException {
FileUtils.close(in);
z.close();
}
protected void finalize() throws Throwable {
try {
close();
} finally {
super.finalize();
}
}
};
}
示例9: getUnixMode
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
* Determine a Resource's Unix mode or return the given default
* value if not available.
*/
private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode) {
int unixMode = defaultMode;
if (zf != null) {
final ZipEntry ze = zf.getEntry(r.getName());
unixMode = ze.getUnixMode();
if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG)
&& !preserve0Permissions) {
unixMode = defaultMode;
}
} else if (r instanceof ArchiveResource) {
unixMode = ((ArchiveResource) r).getMode();
}
return unixMode;
}
示例10: getSetPermissionsWorksForZipResources
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
@Test
public void getSetPermissionsWorksForZipResources() throws IOException {
File f = File.createTempFile("ant", ".zip");
f.deleteOnExit();
try (ZipOutputStream os = new ZipOutputStream(f)) {
ZipEntry e = new ZipEntry("foo");
os.putNextEntry(e);
os.closeEntry();
}
ZipResource r = new ZipResource();
r.setName("foo");
r.setArchive(f);
Set<PosixFilePermission> s =
EnumSet.of(PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE,
PosixFilePermission.OWNER_EXECUTE,
PosixFilePermission.GROUP_READ);
PermissionUtils.setPermissions(r, s, null);
assertEquals(s, PermissionUtils.getPermissions(r, null));
}
示例11: zip
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
private void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) {
File[] fl = f.listFiles();
out.putNextEntry(new ZipEntry(base + File.separator));
base = base.length() == 0 ? "" : base + File.separator;
for (File fl1 : fl) {
zip(out, fl1, base + fl1.getName());
}
} else {
out.putNextEntry(new ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
示例12: compress
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
*
* 方法说明:压缩文件
*
* @param out
* 输出流
* @param f
* 输出文件
* @param base
* 可无
* @throws Exception
*/
private static void compress(ZipOutputStream out, File f, String base) throws Exception
{
if (f.isDirectory()) {
File[] fl = f.listFiles();
out.putNextEntry(new ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
compress(out, fl[i], base + fl[i].getName());
}
} else {
out.putNextEntry(new ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
示例13: unzipToDirectory
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
private static void unzipToDirectory(ZipFile zipFile, File destDir) throws IOException {
byte[] buffer = new byte[4096];
Enumeration entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.isDirectory()) {
File dir = new File(destDir, entry.getName());
InstallUtils.createDirectory(dir);
} else {
File file = new File(destDir, entry.getName());
InstallUtils.createDirectory(file.getParentFile());
OutputStream out = null;
InputStream in = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
in = zipFile.getInputStream(entry);
Unzip.copy(in, out, buffer);
} finally {
InstallUtils.close(in);
InstallUtils.close(out);
}
Unzip.setFilePermissions(file, entry);
}
}
}
示例14: handleDir
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
private void handleDir(File dir, ZipOutputStream zipOut) throws IOException {
FileInputStream fileIn;
File[] files;
files = dir.listFiles();
if (files.length == 0) {// create if empty
this.zipOut.putNextEntry(new ZipEntry(dir.toString() + "/"));
this.zipOut.closeEntry();
} else {// handle directory and file if not empty
for (File fileName : files) {
if (fileName.isDirectory()) {
handleDir(fileName, this.zipOut);
} else {
fileIn = new FileInputStream(fileName);
this.zipOut.putNextEntry(new ZipEntry(fileName.toString()));
while ((this.readedBytes = fileIn.read(this.buf)) > 0) {
this.zipOut.write(this.buf, 0, this.readedBytes);
}
this.zipOut.closeEntry();
}
}
}
}
示例15: putNextEntry
import org.apache.tools.zip.ZipEntry; //导入依赖的package包/类
/**
* Begins writing a new JAR file entry and positions the stream
* to the start of the entry data. This method will also close
* any previous entry. The default compression method will be
* used if no compression method was specified for the entry.
* The current time will be used if the entry has no set modification
* time.
*
* @param ze the ZIP/JAR entry to be written
* @throws java.util.zip.ZipException if a ZIP error has occurred
* @throws IOException if an I/O error has occurred
*/
public void putNextEntry(org.apache.tools.zip.ZipEntry ze) throws IOException
{
if (firstEntry)
{
// Make sure that extra field data for first JAR
// entry includes JAR magic number id.
byte[] edata = ze.getExtra();
if (edata != null && !hasMagic(edata))
{
// Prepend magic to existing extra data
byte[] tmp = new byte[edata.length + 4];
System.arraycopy(tmp, 4, edata, 0, edata.length);
edata = tmp;
}
else
{
edata = new byte[4];
}
set16(edata, 0, JAR_MAGIC); // extra field id
set16(edata, 2, 0); // extra field size
ze.setExtra(edata);
firstEntry = false;
}
super.putNextEntry(ze);
}