summaryrefslogtreecommitdiff
path: root/tools/gnu/classpath/tools
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-05-22 01:21:34 +0000
committerTom Tromey <tromey@redhat.com>2006-05-22 01:21:34 +0000
commit3ea8d02854a062b5555be023f93e91abc8653dbb (patch)
tree28b5c3d3393e56d5c4a59feb3e58a7ccacfca64e /tools/gnu/classpath/tools
parentcd37793f7ca32387dfd3b12b68ac47cba85f878a (diff)
downloadclasspath-3ea8d02854a062b5555be023f93e91abc8653dbb.tar.gz
PR classpath/27688:
* tools/gnu/classpath/tools/jar/Extractor.java (allItems): Now a WorkSet. (initSet): Removed. (shouldExtract): Removed. (run): Updated. * tools/gnu/classpath/tools/jar/WorkSet.java: New file. * tools/gnu/classpath/tools/jar/Lister.java (readUntilEnd): New method. (listJar): Use it. (allItems): New field. (run): Initialize it. (listJar): Use it.
Diffstat (limited to 'tools/gnu/classpath/tools')
-rw-r--r--tools/gnu/classpath/tools/jar/Extractor.java43
-rw-r--r--tools/gnu/classpath/tools/jar/Lister.java24
-rw-r--r--tools/gnu/classpath/tools/jar/WorkSet.java86
3 files changed, 112 insertions, 41 deletions
diff --git a/tools/gnu/classpath/tools/jar/Extractor.java b/tools/gnu/classpath/tools/jar/Extractor.java
index ed647cbfe..203ff0566 100644
--- a/tools/gnu/classpath/tools/jar/Extractor.java
+++ b/tools/gnu/classpath/tools/jar/Extractor.java
@@ -45,9 +45,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -55,8 +52,7 @@ public class Extractor
extends Action
{
// This is a set of all the items specified on the command line.
- // It is null if none were specified.
- private HashSet allItems;
+ private WorkSet allItems;
private void copyFile(InputStream input, File output) throws IOException
{
@@ -72,43 +68,10 @@ public class Extractor
os.close();
}
- private void initSet(ArrayList entries)
- {
- if (entries == null || entries.isEmpty())
- return;
- allItems = new HashSet();
- Iterator it = entries.iterator();
- while (it.hasNext())
- {
- Entry entry = (Entry) it.next();
- int len = entry.name.length();
- while (len > 0 && entry.name.charAt(len - 1) == '/')
- --len;
- String name = entry.name.substring(0, len);
- allItems.add(name);
- }
- }
-
- private boolean shouldExtract(String filename)
- {
- if (allItems == null)
- return true;
- while (filename.length() > 0)
- {
- if (allItems.contains(filename))
- return true;
- int index = filename.lastIndexOf('/');
- if (index == -1)
- break;
- filename = filename.substring(0, index);
- }
- return false;
- }
-
public void run(Main parameters) throws IOException
{
// Figure out what we want to extract.
- initSet(parameters.entries);
+ allItems = new WorkSet(parameters.entries);
// Open the input file.
ZipInputStream zis;
File zfile = parameters.archiveFile;
@@ -125,7 +88,7 @@ public class Extractor
ZipEntry entry = zis.getNextEntry();
if (entry == null)
break;
- if (! shouldExtract(entry.getName()))
+ if (! allItems.contains(entry.getName()))
continue;
File file = new File(entry.getName());
if (entry.isDirectory())
diff --git a/tools/gnu/classpath/tools/jar/Lister.java b/tools/gnu/classpath/tools/jar/Lister.java
index ee4fb725e..98275f789 100644
--- a/tools/gnu/classpath/tools/jar/Lister.java
+++ b/tools/gnu/classpath/tools/jar/Lister.java
@@ -42,6 +42,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Date;
import java.util.zip.ZipEntry;
@@ -50,6 +51,22 @@ import java.util.zip.ZipInputStream;
public class Lister
extends Action
{
+ private WorkSet allItems;
+
+ private long readUntilEnd(InputStream is) throws IOException
+ {
+ byte[] buffer = new byte[5 * 1024];
+ long result = 0;
+ while (true)
+ {
+ int r = is.read(buffer);
+ if (r == -1)
+ break;
+ result += r;
+ }
+ return result;
+ }
+
private void listJar(ZipInputStream zis, boolean verbose) throws IOException
{
MessageFormat format = null;
@@ -60,11 +77,15 @@ public class Lister
ZipEntry entry = zis.getNextEntry();
if (entry == null)
break;
+ if (! allItems.contains(entry.getName()))
+ continue;
if (verbose)
{
+ // Read the stream; entry.getSize() is unreliable.
+ // (Also, we're just going to read it anyway.)
+ long size = readUntilEnd(zis);
// No easy way to right-justify the size using
// MessageFormat -- how odd.
- long size = entry.getSize();
String s = " " + size;
int index = Math.min(s.length() - 5, 5);
System.out.print(s.substring(index));
@@ -79,6 +100,7 @@ public class Lister
public void run(Main parameters) throws IOException
{
+ allItems = new WorkSet(parameters.entries);
File file = parameters.archiveFile;
ZipInputStream zis;
if (file == null || "-".equals(file.getName()))
diff --git a/tools/gnu/classpath/tools/jar/WorkSet.java b/tools/gnu/classpath/tools/jar/WorkSet.java
new file mode 100644
index 000000000..ff0b48786
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/WorkSet.java
@@ -0,0 +1,86 @@
+/* WorkSet.java -- Helper to track what files to work on
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.classpath.tools.jar;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class WorkSet
+{
+ private HashSet allItems;
+
+ private void initSet(ArrayList entries)
+ {
+ if (entries == null || entries.isEmpty())
+ return;
+ allItems = new HashSet();
+ Iterator it = entries.iterator();
+ while (it.hasNext())
+ {
+ Entry entry = (Entry) it.next();
+ int len = entry.name.length();
+ while (len > 0 && entry.name.charAt(len - 1) == '/')
+ --len;
+ String name = entry.name.substring(0, len);
+ allItems.add(name);
+ }
+ }
+
+ public WorkSet(ArrayList entries)
+ {
+ initSet(entries);
+ }
+
+ public boolean contains(String filename)
+ {
+ if (allItems == null)
+ return true;
+ while (filename.length() > 0)
+ {
+ if (allItems.contains(filename))
+ return true;
+ int index = filename.lastIndexOf('/');
+ if (index == -1)
+ break;
+ filename = filename.substring(0, index);
+ }
+ return false;
+ }
+}