OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [jar/] [Lister.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* Lister.java - action to list contents of a jar file
2
 Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
 This file is part of GNU Classpath.
5
 
6
 GNU Classpath is free software; you can redistribute it and/or modify
7
 it under the terms of the GNU General Public License as published by
8
 the Free Software Foundation; either version 2, or (at your option)
9
 any later version.
10
 
11
 GNU Classpath is distributed in the hope that it will be useful, but
12
 WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 General Public License for more details.
15
 
16
 You should have received a copy of the GNU General Public License
17
 along with GNU Classpath; see the file COPYING.  If not, write to the
18
 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
 02110-1301 USA.
20
 
21
 Linking this library statically or dynamically with other modules is
22
 making a combined work based on this library.  Thus, the terms and
23
 conditions of the GNU General Public License cover the whole
24
 combination.
25
 
26
 As a special exception, the copyright holders of this library give you
27
 permission to link this library with independent modules to produce an
28
 executable, regardless of the license terms of these independent
29
 modules, and to copy and distribute the resulting executable under
30
 terms of your choice, provided that you also meet, for each linked
31
 independent module, the terms and conditions of the license of that
32
 module.  An independent module is a module which is not derived from
33
 or based on this library.  If you modify this library, you may extend
34
 this exception to your version of the library, but you are not
35
 obligated to do so.  If you do not wish to do so, delete this
36
 exception statement from your version. */
37
 
38
 
39
package gnu.classpath.tools.jar;
40
 
41
import java.io.BufferedInputStream;
42
import java.io.File;
43
import java.io.FileInputStream;
44
import java.io.IOException;
45
import java.io.InputStream;
46
import java.text.MessageFormat;
47
import java.util.Date;
48
import java.util.zip.ZipEntry;
49
import java.util.zip.ZipInputStream;
50
 
51
public class Lister
52
    extends Action
53
{
54
  private WorkSet allItems;
55
 
56
  private long readUntilEnd(InputStream is) throws IOException
57
  {
58
    byte[] buffer = new byte[5 * 1024];
59
    long result = 0;
60
    while (true)
61
      {
62
        int r = is.read(buffer);
63
        if (r == -1)
64
          break;
65
        result += r;
66
      }
67
    return result;
68
  }
69
 
70
  private void listJar(ZipInputStream zis, boolean verbose) throws IOException
71
  {
72
    MessageFormat format = null;
73
    if (verbose)
74
      format = new MessageFormat(" {0,date,E M dd HH:mm:ss z yyyy} {1}");
75
    while (true)
76
      {
77
        ZipEntry entry = zis.getNextEntry();
78
        if (entry == null)
79
          break;
80
        if (! allItems.contains(entry.getName()))
81
          continue;
82
        if (verbose)
83
          {
84
            // Read the stream; entry.getSize() is unreliable.
85
            // (Also, we're just going to read it anyway.)
86
            long size = readUntilEnd(zis);
87
            // No easy way to right-justify the size using
88
            // MessageFormat -- how odd.
89
            String s = "     " + size;
90
            int index = Math.min(s.length() - 5, 5);
91
            System.out.print(s.substring(index));
92
            Object[] values = new Object[] { new Date(entry.getTime()),
93
                                            entry.getName() };
94
            System.out.println(format.format(values));
95
          }
96
        else
97
          System.out.println(entry.getName());
98
      }
99
  }
100
 
101
  public void run(Main parameters) throws IOException
102
  {
103
    allItems = new WorkSet(parameters.entries);
104
    File file = parameters.archiveFile;
105
    ZipInputStream zis;
106
    if (file == null || "-".equals(file.getName()))
107
      zis = new ZipInputStream(System.in);
108
    else
109
      zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
110
    listJar(zis, parameters.verbose);
111
  }
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.