summaryrefslogtreecommitdiff
path: root/src/proguard/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/io')
-rw-r--r--src/proguard/io/CascadingDataEntryWriter.java94
-rw-r--r--src/proguard/io/ClassFilter.java57
-rw-r--r--src/proguard/io/ClassReader.java115
-rw-r--r--src/proguard/io/ClassRewriter.java80
-rw-r--r--src/proguard/io/DataEntry.java62
-rw-r--r--src/proguard/io/DataEntryClassWriter.java85
-rw-r--r--src/proguard/io/DataEntryCopier.java360
-rw-r--r--src/proguard/io/DataEntryDirectoryFilter.java38
-rw-r--r--src/proguard/io/DataEntryFilter.java38
-rw-r--r--src/proguard/io/DataEntryNameFilter.java54
-rw-r--r--src/proguard/io/DataEntryObfuscator.java150
-rw-r--r--src/proguard/io/DataEntryParentFilter.java51
-rw-r--r--src/proguard/io/DataEntryPump.java43
-rw-r--r--src/proguard/io/DataEntryReader.java38
-rw-r--r--src/proguard/io/DataEntryRenamer.java104
-rw-r--r--src/proguard/io/DataEntryRewriter.java148
-rw-r--r--src/proguard/io/DataEntryWriter.java73
-rw-r--r--src/proguard/io/DirectoryFilter.java52
-rw-r--r--src/proguard/io/DirectoryPump.java78
-rw-r--r--src/proguard/io/DirectoryWriter.java165
-rw-r--r--src/proguard/io/FileDataEntry.java96
-rw-r--r--src/proguard/io/FilteredDataEntryReader.java90
-rw-r--r--src/proguard/io/FilteredDataEntryWriter.java125
-rw-r--r--src/proguard/io/Finisher.java37
-rw-r--r--src/proguard/io/JarReader.java75
-rw-r--r--src/proguard/io/JarWriter.java234
-rw-r--r--src/proguard/io/ManifestRewriter.java211
-rw-r--r--src/proguard/io/NameFilter.java83
-rw-r--r--src/proguard/io/ParentDataEntryWriter.java75
-rw-r--r--src/proguard/io/RenamedDataEntry.java83
-rw-r--r--src/proguard/io/ZipDataEntry.java105
-rw-r--r--src/proguard/io/package.html4
32 files changed, 0 insertions, 3103 deletions
diff --git a/src/proguard/io/CascadingDataEntryWriter.java b/src/proguard/io/CascadingDataEntryWriter.java
deleted file mode 100644
index 17c1946..0000000
--- a/src/proguard/io/CascadingDataEntryWriter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-/**
- * This DataEntryWriter delegates to a given DataEntryWriter, or failing that,
- * to another given DataEntryWriter.
- *
- * @author Eric Lafortune
- */
-public class CascadingDataEntryWriter implements DataEntryWriter
-{
- private DataEntryWriter dataEntryWriter1;
- private DataEntryWriter dataEntryWriter2;
-
-
- /**
- * Creates a new CascadingDataEntryWriter.
- * @param dataEntryWriter1 the DataEntryWriter to which the writing will be
- * delegated first.
- * @param dataEntryWriter2 the DataEntryWriter to which the writing will be
- * delegated, if the first one can't provide an
- * output stream.
- */
- public CascadingDataEntryWriter(DataEntryWriter dataEntryWriter1,
- DataEntryWriter dataEntryWriter2)
- {
- this.dataEntryWriter1 = dataEntryWriter1;
- this.dataEntryWriter2 = dataEntryWriter2;
- }
-
-
- // Implementations for DataEntryWriter.
-
-
- public boolean createDirectory(DataEntry dataEntry) throws IOException
- {
- // Try to create a directory with the first data entry writer, or
- // otherwise with the second data entry writer.
- return dataEntryWriter1.createDirectory(dataEntry) ||
- dataEntryWriter2.createDirectory(dataEntry);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry, null);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException
- {
- // Try to get an output stream from the first data entry writer.
- OutputStream outputStream =
- dataEntryWriter1.getOutputStream(dataEntry, finisher);
-
- // Return it, if it's not null. Otherwise try to get an output stream
- // from the second data entry writer.
- return outputStream != null ?
- outputStream :
- dataEntryWriter2.getOutputStream(dataEntry, finisher);
- }
-
-
- public void close() throws IOException
- {
- dataEntryWriter1.close();
- dataEntryWriter2.close();
-
- dataEntryWriter1 = null;
- dataEntryWriter2 = null;
- }
-}
diff --git a/src/proguard/io/ClassFilter.java b/src/proguard/io/ClassFilter.java
deleted file mode 100644
index c89f9f6..0000000
--- a/src/proguard/io/ClassFilter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-import proguard.util.ExtensionMatcher;
-
-
-/**
- * This DataEntryReader delegates to one of two other DataEntryReader instances,
- * depending on the extension of the data entry.
- *
- * @author Eric Lafortune
- */
-public class ClassFilter extends FilteredDataEntryReader
-{
- /**
- * Creates a new ClassFilter that delegates reading classes to the
- * given reader.
- */
- public ClassFilter(DataEntryReader classReader)
- {
- this(classReader, null);
- }
-
-
- /**
- * Creates a new ClassFilter that delegates to either of the two given
- * readers.
- */
- public ClassFilter(DataEntryReader classReader,
- DataEntryReader dataEntryReader)
- {
- super(new DataEntryNameFilter(
- new ExtensionMatcher(ClassConstants.CLASS_FILE_EXTENSION)),
- classReader,
- dataEntryReader);
- }
-}
diff --git a/src/proguard/io/ClassReader.java b/src/proguard/io/ClassReader.java
deleted file mode 100644
index 124160c..0000000
--- a/src/proguard/io/ClassReader.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.*;
-import proguard.classfile.io.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.ClassVisitor;
-
-import java.io.*;
-
-/**
- * This DataEntryReader applies a given ClassVisitor to the class
- * definitions that it reads.
- * <p>
- * Class files are read as ProgramClass objects or LibraryClass objects,
- * depending on the <code>isLibrary</code> flag.
- * <p>
- * In case of libraries, only public classes are considered, if the
- * <code>skipNonPublicLibraryClasses</code> flag is set.
- *
- * @author Eric Lafortune
- */
-public class ClassReader implements DataEntryReader
-{
- private final boolean isLibrary;
- private final boolean skipNonPublicLibraryClasses;
- private final boolean skipNonPublicLibraryClassMembers;
- private final WarningPrinter warningPrinter;
- private final ClassVisitor classVisitor;
-
-
- /**
- * Creates a new DataEntryClassFilter for reading the specified
- * Clazz objects.
- */
- public ClassReader(boolean isLibrary,
- boolean skipNonPublicLibraryClasses,
- boolean skipNonPublicLibraryClassMembers,
- WarningPrinter warningPrinter,
- ClassVisitor classVisitor)
- {
- this.isLibrary = isLibrary;
- this.skipNonPublicLibraryClasses = skipNonPublicLibraryClasses;
- this.skipNonPublicLibraryClassMembers = skipNonPublicLibraryClassMembers;
- this.warningPrinter = warningPrinter;
- this.classVisitor = classVisitor;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- try
- {
- // Get the input stream.
- InputStream inputStream = dataEntry.getInputStream();
-
- // Wrap it into a data input stream.
- DataInputStream dataInputStream = new DataInputStream(inputStream);
-
- // Create a Clazz representation.
- Clazz clazz;
- if (isLibrary)
- {
- clazz = new LibraryClass();
- clazz.accept(new LibraryClassReader(dataInputStream, skipNonPublicLibraryClasses, skipNonPublicLibraryClassMembers));
- }
- else
- {
- clazz = new ProgramClass();
- clazz.accept(new ProgramClassReader(dataInputStream));
- }
-
- // Apply the visitor, if we have a real class.
- String className = clazz.getName();
- if (className != null)
- {
- if (!dataEntry.getName().replace(File.pathSeparatorChar, ClassConstants.PACKAGE_SEPARATOR).equals(className+ClassConstants.CLASS_FILE_EXTENSION) &&
- warningPrinter != null)
- {
- warningPrinter.print(className,
- "Warning: class [" + dataEntry.getName() + "] unexpectedly contains class [" + ClassUtil.externalClassName(className) + "]");
- }
-
- clazz.accept(classVisitor);
- }
-
- dataEntry.closeInputStream();
- }
- catch (Exception ex)
- {
- throw (IOException)new IOException("Can't process class ["+dataEntry.getName()+"] ("+ex.getMessage()+")").initCause(ex);
- }
- }
-}
diff --git a/src/proguard/io/ClassRewriter.java b/src/proguard/io/ClassRewriter.java
deleted file mode 100644
index fab9366..0000000
--- a/src/proguard/io/ClassRewriter.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.*;
-import proguard.classfile.io.ProgramClassWriter;
-
-import java.io.*;
-
-
-/**
- * This DataEntryReader reads class entries and writes their corresponding
- * versions from the ClassPool to a given DataEntryWriter.
- *
- * @author Eric Lafortune
- */
-public class ClassRewriter implements DataEntryReader
-{
- private final ClassPool classPool;
- private final DataEntryWriter dataEntryWriter;
-
-
- public ClassRewriter(ClassPool classPool,
- DataEntryWriter dataEntryWriter)
- {
- this.classPool = classPool;
- this.dataEntryWriter = dataEntryWriter;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- String inputName = dataEntry.getName();
- String className = inputName.substring(0, inputName.length() - ClassConstants.CLASS_FILE_EXTENSION.length());
-
- // Find the modified class corrsponding to the input entry.
- ProgramClass programClass = (ProgramClass)classPool.getClass(className);
- if (programClass != null)
- {
- // Rename the data entry if necessary.
- String newClassName = programClass.getName();
- if (!className.equals(newClassName))
- {
- dataEntry = new RenamedDataEntry(dataEntry, newClassName + ClassConstants.CLASS_FILE_EXTENSION);
- }
-
- // Get the output entry corresponding to this input entry.
- OutputStream outputStream = dataEntryWriter.getOutputStream(dataEntry);
- if (outputStream != null)
- {
- // Write the class to the output entry.
- DataOutputStream classOutputStream = new DataOutputStream(outputStream);
-
- new ProgramClassWriter(classOutputStream).visitProgramClass(programClass);
-
- classOutputStream.flush();
- }
- }
- }
-}
diff --git a/src/proguard/io/DataEntry.java b/src/proguard/io/DataEntry.java
deleted file mode 100644
index 59946c9..0000000
--- a/src/proguard/io/DataEntry.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-/**
- * This interface describes a data entry, e.g. a ZIP entry, a file, or a
- * directory.
- *
- * @author Eric Lafortune
- */
-public interface DataEntry
-{
- /**
- * Returns the name of this data entry.
- */
- public String getName();
-
- /**
- * Returns whether the data entry represents a directory.
- */
- public boolean isDirectory();
-
-
- /**
- * Returns an input stream for reading the content of this data entry.
- * The data entry may not represent a directory.
- */
- public InputStream getInputStream() throws IOException;
-
-
- /**
- * Closes the previously retrieved InputStream.
- */
- public void closeInputStream() throws IOException;
-
-
- /**
- * Returns the parent of this data entry, or <code>null</null> if it doesn't
- * have one.
- */
- public DataEntry getParent();
-}
diff --git a/src/proguard/io/DataEntryClassWriter.java b/src/proguard/io/DataEntryClassWriter.java
deleted file mode 100644
index 205cce1..0000000
--- a/src/proguard/io/DataEntryClassWriter.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.*;
-import proguard.classfile.io.ProgramClassWriter;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-import java.io.*;
-
-/**
- * This ClassVisitor writes out the ProgramClass objects that it visits to the
- * given DataEntry, modified to have the correct name.
- *
- * @author Eric Lafortune
- */
-public class DataEntryClassWriter
-extends SimplifiedVisitor
-implements ClassVisitor
-{
- private final DataEntryWriter dataEntryWriter;
- private final DataEntry templateDataEntry;
-
-
- /**
- * Creates a new DataEntryClassWriter for writing to the given
- * DataEntryWriter, based on the given template DataEntry.
- */
- public DataEntryClassWriter(DataEntryWriter dataEntryWriter,
- DataEntry templateDataEntry)
- {
- this.dataEntryWriter = dataEntryWriter;
- this.templateDataEntry = templateDataEntry;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Rename the data entry if necessary.
- String actualClassName = programClass.getName();
- DataEntry actualDataEntry =
- new RenamedDataEntry(templateDataEntry,
- actualClassName + ClassConstants.CLASS_FILE_EXTENSION);
-
- try
- {
- // Get the output entry corresponding to this input entry.
- OutputStream outputStream = dataEntryWriter.getOutputStream(actualDataEntry);
- if (outputStream != null)
- {
- // Write the class to the output entry.
- DataOutputStream classOutputStream = new DataOutputStream(outputStream);
-
- new ProgramClassWriter(classOutputStream).visitProgramClass(programClass);
-
- classOutputStream.flush();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("Can't write program class ["+actualClassName+"] to ["+actualDataEntry+"] ("+e.getMessage()+")", e);
- }
- }
-}
diff --git a/src/proguard/io/DataEntryCopier.java b/src/proguard/io/DataEntryCopier.java
deleted file mode 100644
index 63b2fa9..0000000
--- a/src/proguard/io/DataEntryCopier.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.util.ExtensionMatcher;
-
-import java.io.*;
-
-
-/**
- * This DataEntryReader writes the ZIP entries and files that it reads to a
- * given DataEntryWriter.
- *
- * @author Eric Lafortune
- */
-public class DataEntryCopier implements DataEntryReader
-{
- private static final int BUFFER_SIZE = 1024;
-
- private final DataEntryWriter dataEntryWriter;
- private final byte[] buffer = new byte[BUFFER_SIZE];
-
-
-
- public DataEntryCopier(DataEntryWriter dataEntryWriter)
- {
- this.dataEntryWriter = dataEntryWriter;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- try
- {
- if (dataEntry.isDirectory())
- {
- dataEntryWriter.createDirectory(dataEntry);
- }
- else
- {
- // Get the output entry corresponding to this input entry.
- OutputStream outputStream = dataEntryWriter.getOutputStream(dataEntry);
- if (outputStream != null)
- {
- InputStream inputStream = dataEntry.getInputStream();
-
- try
- {
- // Copy the data from the input entry to the output entry.
- copyData(inputStream, outputStream);
- }
- finally
- {
- // Close the data entries.
- dataEntry.closeInputStream();
- }
- }
- }
- }
- catch (IOException ex)
- {
- System.err.println("Warning: can't write resource [" + dataEntry.getName() + "] (" + ex.getMessage() + ")");
- }
- catch (Exception ex)
- {
- throw (IOException)new IOException("Can't write resource ["+dataEntry.getName()+"] ("+ex.getMessage()+")").initCause(ex);
- }
- }
-
-
- /**
- * Copies all data that it can read from the given input stream to the
- * given output stream.
- */
- protected void copyData(InputStream inputStream,
- OutputStream outputStream)
- throws IOException
- {
- while (true)
- {
- int count = inputStream.read(buffer);
- if (count < 0)
- {
- break;
- }
- outputStream.write(buffer, 0, count);
- }
-
- outputStream.flush();
- }
-
-
- /**
- * A main method for testing file/jar/war/directory copying.
- */
- public static void main(String[] args)
- {
- try
- {
- String input = args[0];
- String output = args[1];
-
- boolean outputIsApk = output.endsWith(".apk") ||
- output.endsWith(".ap_");
- boolean outputIsJar = output.endsWith(".jar");
- boolean outputIsAar = output.endsWith(".aar");
- boolean outputIsWar = output.endsWith(".war");
- boolean outputIsEar = output.endsWith(".ear");
- boolean outputIsZip = output.endsWith(".zip");
-
- DataEntryWriter writer = new DirectoryWriter(new File(output),
- outputIsApk ||
- outputIsJar ||
- outputIsAar ||
- outputIsWar ||
- outputIsEar ||
- outputIsZip);
-
- // Zip up any zips, if necessary.
- DataEntryWriter zipWriter = new JarWriter(writer);
- if (outputIsZip)
- {
- // Always zip.
- writer = zipWriter;
- }
- else
- {
- // Only zip up zips.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".zip"))),
- zipWriter,
- writer);
- }
-
- // Zip up any ears, if necessary.
- DataEntryWriter earWriter = new JarWriter(writer);
- if (outputIsEar)
- {
- // Always zip.
- writer = earWriter;
- }
- else
- {
- // Only zip up ears.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".ear"))),
- earWriter,
- writer);
- }
-
- // Zip up any wars, if necessary.
- DataEntryWriter warWriter = new JarWriter(writer);
- if (outputIsWar)
- {
- // Always zip.
- writer = warWriter;
- }
- else
- {
- // Only zip up wars.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".war"))),
- warWriter,
- writer);
- }
-
- // Zip up any aars, if necessary.
- DataEntryWriter aarWriter = new JarWriter(writer);
- if (outputIsAar)
- {
- // Always zip.
- writer = aarWriter;
- }
- else
- {
- // Only zip up aars.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".aar"))),
- aarWriter,
- writer);
- }
-
- // Zip up any jars, if necessary.
- DataEntryWriter jarWriter = new JarWriter(writer);
- if (outputIsJar)
- {
- // Always zip.
- writer = jarWriter;
- }
- else
- {
- // Only zip up jars.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".jar"))),
- jarWriter,
- writer);
- }
-
- // Zip up any apks, if necessary.
- DataEntryWriter apkWriter = new JarWriter(writer);
- if (outputIsApk)
- {
- // Always zip.
- writer = apkWriter;
- }
- else
- {
- // Only zip up apks.
- writer = new FilteredDataEntryWriter(new DataEntryParentFilter(
- new DataEntryNameFilter(
- new ExtensionMatcher(".apk"))),
- apkWriter,
- writer);
- }
-
-
- // Create the copying DataEntryReader.
- DataEntryReader reader = new DataEntryCopier(writer);
-
- boolean inputIsApk = input.endsWith(".apk") ||
- input.endsWith(".ap_");
- boolean inputIsJar = input.endsWith(".jar");
- boolean inputIsAar = input.endsWith(".aar");
- boolean inputIsWar = input.endsWith(".war");
- boolean inputIsEar = input.endsWith(".ear");
- boolean inputIsZip = input.endsWith(".zip");
-
- // Unzip any apks, if necessary.
- DataEntryReader apkReader = new JarReader(reader);
- if (inputIsApk)
- {
- // Always unzip.
- reader = apkReader;
- }
- else
- {
- // Only unzip apk entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".apk")),
- apkReader,
- reader);
-
- // Unzip any jars, if necessary.
- DataEntryReader jarReader = new JarReader(reader);
- if (inputIsJar)
- {
- // Always unzip.
- reader = jarReader;
- }
- else
- {
- // Only unzip jar entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".jar")),
- jarReader,
- reader);
-
- // Unzip any aars, if necessary.
- DataEntryReader aarReader = new JarReader(reader);
- if (inputIsAar)
- {
- // Always unzip.
- reader = aarReader;
- }
- else
- {
- // Only unzip aar entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".aar")),
- aarReader,
- reader);
-
- // Unzip any wars, if necessary.
- DataEntryReader warReader = new JarReader(reader);
- if (inputIsWar)
- {
- // Always unzip.
- reader = warReader;
- }
- else
- {
- // Only unzip war entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".war")),
- warReader,
- reader);
-
- // Unzip any ears, if necessary.
- DataEntryReader earReader = new JarReader(reader);
- if (inputIsEar)
- {
- // Always unzip.
- reader = earReader;
- }
- else
- {
- // Only unzip ear entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".ear")),
- earReader,
- reader);
-
- // Unzip any zips, if necessary.
- DataEntryReader zipReader = new JarReader(reader);
- if (inputIsZip)
- {
- // Always unzip.
- reader = zipReader;
- }
- else
- {
- // Only unzip zip entries.
- reader = new FilteredDataEntryReader(new DataEntryNameFilter(
- new ExtensionMatcher(".zip")),
- zipReader,
- reader);
- }
- }
- }
- }
- }
- }
-
- DirectoryPump directoryReader = new DirectoryPump(new File(input));
-
- directoryReader.pumpDataEntries(reader);
-
- writer.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-}
diff --git a/src/proguard/io/DataEntryDirectoryFilter.java b/src/proguard/io/DataEntryDirectoryFilter.java
deleted file mode 100644
index a9b2c8b..0000000
--- a/src/proguard/io/DataEntryDirectoryFilter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-/**
- * This DataEntryFilter filters data entries based on whether they represent
- * directories.
- *
- * @author Eric Lafortune
- */
-public class DataEntryDirectoryFilter
-implements DataEntryFilter
-{
- // Implementations for DataEntryFilter.
-
- public boolean accepts(DataEntry dataEntry)
- {
- return dataEntry != null && dataEntry.isDirectory();
- }
-} \ No newline at end of file
diff --git a/src/proguard/io/DataEntryFilter.java b/src/proguard/io/DataEntryFilter.java
deleted file mode 100644
index 0b604ba..0000000
--- a/src/proguard/io/DataEntryFilter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-
-/**
- * This interface provides a method to filter data entries.
- *
- * @author Eric Lafortune
- */
-public interface DataEntryFilter
-{
- /**
- * Checks whether the filter accepts the given data entry.
- * @param dataEntry the data entry to filter.
- * @return a boolean indicating whether the filter accepts the given data
- * entry.
- */
- public boolean accepts(DataEntry dataEntry);
-}
diff --git a/src/proguard/io/DataEntryNameFilter.java b/src/proguard/io/DataEntryNameFilter.java
deleted file mode 100644
index bc676c0..0000000
--- a/src/proguard/io/DataEntryNameFilter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.util.StringMatcher;
-
-/**
- * This DataEntryFilter filters data entries based on whether their names match
- * a given StringMatcher.
- *
- * @author Eric Lafortune
- */
-public class DataEntryNameFilter
-implements DataEntryFilter
-{
- private final StringMatcher stringMatcher;
-
-
- /**
- * Creates a new DataEntryNameFilter.
- * @param stringMatcher the string matcher that will be applied to the names
- * of the filtered data entries.
- */
- public DataEntryNameFilter(StringMatcher stringMatcher)
- {
- this.stringMatcher = stringMatcher;
- }
-
-
- // Implementations for DataEntryFilter.
-
- public boolean accepts(DataEntry dataEntry)
- {
- return dataEntry != null && stringMatcher.matches(dataEntry.getName());
- }
-}
diff --git a/src/proguard/io/DataEntryObfuscator.java b/src/proguard/io/DataEntryObfuscator.java
deleted file mode 100644
index aabb0e8..0000000
--- a/src/proguard/io/DataEntryObfuscator.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.*;
-import proguard.classfile.util.ClassUtil;
-
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * This DataEntryReader delegates to another DataEntryReader, renaming the
- * data entries based on the renamed classes in the given ClassPool.
- *
- * @author Eric Lafortune
- */
-public class DataEntryObfuscator implements DataEntryReader
-{
- private final ClassPool classPool;
- private final Map packagePrefixMap;
- private final DataEntryReader dataEntryReader;
-
-
- /**
- * Creates a new DataEntryObfuscator.
- * @param classPool the class pool that maps from old names to new
- * names.
- * @param packagePrefixMap the map from old package prefixes to new package
- * prefixes.
- * @param dataEntryReader the DataEntryReader to which calls will be
- * delegated.
- */
- public DataEntryObfuscator(ClassPool classPool,
- Map packagePrefixMap,
- DataEntryReader dataEntryReader)
- {
- this.classPool = classPool;
- this.packagePrefixMap = packagePrefixMap;
- this.dataEntryReader = dataEntryReader;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- // Delegate to the actual data entry reader.
- dataEntryReader.read(renamedDataEntry(dataEntry));
- }
-
-
- /**
- * Create a renamed data entry, if possible.
- */
- private DataEntry renamedDataEntry(DataEntry dataEntry)
- {
- String dataEntryName = dataEntry.getName();
-
- // Try to find a corresponding class name by removing increasingly
- // long suffixes.
- for (int suffixIndex = dataEntryName.length() - 1;
- suffixIndex > 0;
- suffixIndex--)
- {
- char c = dataEntryName.charAt(suffixIndex);
- if (!Character.isLetterOrDigit(c))
- {
- // Chop off the suffix.
- String className = dataEntryName.substring(0, suffixIndex);
-
- // Did we get to the package separator?
- if (c == ClassConstants.PACKAGE_SEPARATOR)
- {
- break;
- }
-
- // Is there a class corresponding to the data entry?
- Clazz clazz = classPool.getClass(className);
- if (clazz != null)
- {
- // Did the class get a new name?
- String newClassName = clazz.getName();
- if (!className.equals(newClassName))
- {
- // Return a renamed data entry.
- String newDataEntryName =
- newClassName + dataEntryName.substring(suffixIndex);
-
- return new RenamedDataEntry(dataEntry, newDataEntryName);
- }
- else
- {
- // Otherwise stop looking.
- return dataEntry;
- }
- }
- }
- }
-
- // Try to find a corresponding package name by increasingly removing
- // more subpackages.
- String packagePrefix = dataEntryName;
- do
- {
- // Chop off the class name or the last subpackage name.
- packagePrefix = ClassUtil.internalPackagePrefix(packagePrefix);
-
- // Is there a package corresponding to the package prefix?
- String newPackagePrefix = (String)packagePrefixMap.get(packagePrefix);
- if (newPackagePrefix != null)
- {
- // Did the package get a new name?
- if (!packagePrefix.equals(newPackagePrefix))
- {
- // Return a renamed data entry.
- String newDataEntryName =
- newPackagePrefix + dataEntryName.substring(packagePrefix.length());
-
- return new RenamedDataEntry(dataEntry, newDataEntryName);
- }
- else
- {
- // Otherwise stop looking.
- return dataEntry;
- }
- }
- }
- while (packagePrefix.length() > 0);
-
- return dataEntry;
- }
-}
diff --git a/src/proguard/io/DataEntryParentFilter.java b/src/proguard/io/DataEntryParentFilter.java
deleted file mode 100644
index 1d4d1e4..0000000
--- a/src/proguard/io/DataEntryParentFilter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-/**
- * This DataEntryFilter delegates filtering to a DataEntryFilter for its parent.
- *
- * @author Eric Lafortune
- */
-public class DataEntryParentFilter
-implements DataEntryFilter
-{
- private final DataEntryFilter dataEntryFilter;
-
-
- /**
- * Creates a new ParentFilter.
- * @param dataEntryFilter the filter that will be applied to the data
- * entry's parent.
- */
- public DataEntryParentFilter(DataEntryFilter dataEntryFilter)
- {
- this.dataEntryFilter = dataEntryFilter;
- }
-
-
- // Implementations for DataEntryFilter.
-
- public boolean accepts(DataEntry dataEntry)
- {
- return dataEntry != null && dataEntryFilter.accepts(dataEntry.getParent());
- }
-}
diff --git a/src/proguard/io/DataEntryPump.java b/src/proguard/io/DataEntryPump.java
deleted file mode 100644
index 6cdaef3..0000000
--- a/src/proguard/io/DataEntryPump.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.IOException;
-
-
-/**
- * This interface provides a method to pump data entries. The implementation
- * determines the source and the type of the data entries. Typical examples
- * are zip entries coming from a zip file of file entries coming from a
- * directory structure. The reader can for instance collect the classes,
- * or copy the resource files that are presented.
- *
- * @author Eric Lafortune
- */
-public interface DataEntryPump
-{
- /**
- * Applies the given DataEntryReader to all data entries that the
- * implementation can provide.
- */
- public void pumpDataEntries(DataEntryReader dataEntryReader)
- throws IOException;
-}
diff --git a/src/proguard/io/DataEntryReader.java b/src/proguard/io/DataEntryReader.java
deleted file mode 100644
index d03124a..0000000
--- a/src/proguard/io/DataEntryReader.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.IOException;
-
-
-/**
- * This interface provides methods for reading data entries. The implementation
- * determines what to do with the read data, if anything.
- *
- * @author Eric Lafortune
- */
-public interface DataEntryReader
-{
- /**
- * Reads the given data entry.
- */
- public void read(DataEntry dataEntry) throws IOException;
-}
diff --git a/src/proguard/io/DataEntryRenamer.java b/src/proguard/io/DataEntryRenamer.java
deleted file mode 100644
index c8bb319..0000000
--- a/src/proguard/io/DataEntryRenamer.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * This DataEntryReader delegates to another DataEntryReader, renaming the
- * data entries based on the given map. Entries whose name does not appear
- * in the map may be passed to an alternative DataEntryReader.
- *
- * @author Eric Lafortune
- */
-public class DataEntryRenamer implements DataEntryReader
-{
- private final Map nameMap;
- private final DataEntryReader renamedDataEntryReader;
- private final DataEntryReader missingDataEntryReader;
-
-
- /**
- * Creates a new DataEntryRenamer.
- * @param nameMap the map from old names to new names.
- * @param renamedDataEntryReader the DataEntryReader to which renamed data
- * entries will be passed.
- */
- public DataEntryRenamer(Map nameMap,
- DataEntryReader renamedDataEntryReader)
- {
- this(nameMap, renamedDataEntryReader, null);
- }
-
-
- /**
- * Creates a new DataEntryRenamer.
- * @param nameMap the map from old names to new names.
- * @param renamedDataEntryReader the DataEntryReader to which renamed data
- * entries will be passed.
- * @param missingDataEntryReader the optional DataEntryReader to which data
- * entries that can't be renamed will be
- * passed.
- */
- public DataEntryRenamer(Map nameMap,
- DataEntryReader renamedDataEntryReader,
- DataEntryReader missingDataEntryReader)
- {
- this.nameMap = nameMap;
- this.renamedDataEntryReader = renamedDataEntryReader;
- this.missingDataEntryReader = missingDataEntryReader;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- String name = dataEntry.getName();
-
- // Add a directory separator if necessary.
- if (dataEntry.isDirectory() &&
- name.length() > 0)
- {
- name += ClassConstants.PACKAGE_SEPARATOR;
- }
-
- String newName = (String)nameMap.get(name);
- if (newName != null)
- {
- // Remove the directory separator if necessary.
- if (dataEntry.isDirectory() &&
- newName.length() > 0)
- {
- newName = newName.substring(0, newName.length() - 1);
- }
-
- renamedDataEntryReader.read(new RenamedDataEntry(dataEntry, newName));
- }
- else if (missingDataEntryReader != null)
- {
- missingDataEntryReader.read(dataEntry);
- }
- }
-}
diff --git a/src/proguard/io/DataEntryRewriter.java b/src/proguard/io/DataEntryRewriter.java
deleted file mode 100644
index 666aa0d..0000000
--- a/src/proguard/io/DataEntryRewriter.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.*;
-
-import java.io.*;
-
-/**
- * This DataEntryReader writes the resource data entries that it reads to a
- * given DataEntryWriter, updating their contents based on the renamed classes
- * in the given ClassPool.
- *
- * @author Eric Lafortune
- */
-public class DataEntryRewriter extends DataEntryCopier
-{
- private final ClassPool classPool;
-
-
- /**
- * Creates a new DataEntryRewriter.
- */
- public DataEntryRewriter(ClassPool classPool,
- DataEntryWriter dataEntryWriter)
- {
- super(dataEntryWriter);
-
- this.classPool = classPool;
- }
-
-
- // Implementations for DataEntryCopier.
-
- protected void copyData(InputStream inputStream,
- OutputStream outputStream)
- throws IOException
- {
- Reader reader = new BufferedReader(new InputStreamReader(inputStream));
- Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
-
- copyData(reader, writer);
-
- writer.flush();
- outputStream.flush();
- }
-
-
- /**
- * Copies all data that it can read from the given reader to the given
- * writer.
- */
- protected void copyData(Reader reader,
- Writer writer)
- throws IOException
- {
- StringBuffer word = new StringBuffer();
-
- while (true)
- {
- int i = reader.read();
- if (i < 0)
- {
- break;
- }
-
- // Is the character part of a word?
- char c = (char)i;
- if (Character.isJavaIdentifierPart(c) ||
- c == '.' ||
- c == '-')
- {
- // Collect the characters in this word.
- word.append(c);
- }
- else
- {
- // Write out the updated word, if any.
- writeUpdatedWord(writer, word.toString());
- word.setLength(0);
-
- // Write out the character that terminated it.
- writer.write(c);
- }
- }
-
- // Write out the final word.
- writeUpdatedWord(writer, word.toString());
- }
-
-
- // Small utility methods.
-
- /**
- * Writes the given word to the given writer, after having adapted it,
- * based on the renamed class names.
- */
- private void writeUpdatedWord(Writer writer, String word)
- throws IOException
- {
- if (word.length() > 0)
- {
- String newWord = word;
-
- boolean containsDots = word.indexOf('.') >= 0;
-
- // Replace dots by forward slashes.
- String className = containsDots ?
- word.replace('.', ClassConstants.PACKAGE_SEPARATOR) :
- word;
-
- // Find the class corrsponding to the word.
- Clazz clazz = classPool.getClass(className);
- if (clazz != null)
- {
- // Update the word if necessary.
- String newClassName = clazz.getName();
- if (!className.equals(newClassName))
- {
- // Replace forward slashes by dots.
- newWord = containsDots ?
- newClassName.replace(ClassConstants.PACKAGE_SEPARATOR, '.') :
- newClassName;
- }
- }
-
- writer.write(newWord);
- }
- }
-}
diff --git a/src/proguard/io/DataEntryWriter.java b/src/proguard/io/DataEntryWriter.java
deleted file mode 100644
index 5dac1e3..0000000
--- a/src/proguard/io/DataEntryWriter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-
-/**
- * This interface provides methods for writing data entries, such as ZIP entries
- * or files. The implementation determines to which type of data entry the
- * data will be written.
- *
- * @author Eric Lafortune
- */
-public interface DataEntryWriter
-{
- /**
- * Creates a directory.
- * @param dataEntry the data entry for which the directory is to be created.
- * @return whether the directory has been created.
- */
- public boolean createDirectory(DataEntry dataEntry) throws IOException;
-
-
- /**
- * Returns an output stream for writing data. The caller must not close
- * the output stream; closing the output stream is the responsibility of
- * the implementation of this interface.
- * @param dataEntry the data entry for which the output stream is to be created.
- * @return the output stream. The stream may be <code>null</code> to indicate
- * that the data entry should not be written.
- */
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException;
-
-
- /**
- * Returns an output stream for writing data. The caller must not close
- * the output stream; closing the output stream is the responsibility of
- * the implementation of this interface.
- * @param dataEntry the data entry for which the output stream is to be created.
- * @param finisher the optional finisher that will be called before this
- * class closes the output stream (at some later point in
- * time) that will be returned (now).
- * @return the output stream. The stream may be <code>null</code> to indicate
- * that the data entry should not be written.
- */
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException;
-
-
- /**
- * Finishes writing all data entries.
- */
- public void close() throws IOException;
-}
diff --git a/src/proguard/io/DirectoryFilter.java b/src/proguard/io/DirectoryFilter.java
deleted file mode 100644
index ebdf4c4..0000000
--- a/src/proguard/io/DirectoryFilter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-/**
- * This DataEntryReader delegates to one of two other DataEntryReader instances,
- * depending on whether the data entry represents a directory or not.
- *
- * @author Eric Lafortune
- */
-public class DirectoryFilter extends FilteredDataEntryReader
-{
- /**
- * Creates a new ClassFilter that delegates reading directories to the
- * given reader.
- */
- public DirectoryFilter(DataEntryReader directoryReader)
- {
- this (directoryReader, null);
- }
-
-
- /**
- * Creates a new ClassFilter that delegates to either of the two given
- * readers.
- */
- public DirectoryFilter(DataEntryReader directoryReader,
- DataEntryReader otherReader)
- {
- super(new DataEntryDirectoryFilter(),
- directoryReader,
- otherReader);
- }
-} \ No newline at end of file
diff --git a/src/proguard/io/DirectoryPump.java b/src/proguard/io/DirectoryPump.java
deleted file mode 100644
index fe387ca..0000000
--- a/src/proguard/io/DirectoryPump.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-
-/**
- * This class can read a given file or directory, recursively, applying a given
- * DataEntryReader to all files it comes across.
- *
- * @author Eric Lafortune
- */
-public class DirectoryPump implements DataEntryPump
-{
- private final File directory;
-
-
- public DirectoryPump(File directory)
- {
- this.directory = directory;
- }
-
-
- // Implementations for DataEntryPump.
-
- public void pumpDataEntries(DataEntryReader dataEntryReader)
- throws IOException
- {
- if (!directory.exists())
- {
- throw new IOException("No such file or directory");
- }
-
- readFiles(directory, dataEntryReader);
- }
-
-
- /**
- * Reads the given subdirectory recursively, applying the given DataEntryReader
- * to all files that are encountered.
- */
- private void readFiles(File file, DataEntryReader dataEntryReader)
- throws IOException
- {
- // Pass the file data entry to the reader.
- dataEntryReader.read(new FileDataEntry(directory, file));
-
- if (file.isDirectory())
- {
- // Recurse into the subdirectory.
- File[] files = file.listFiles();
-
- for (int index = 0; index < files.length; index++)
- {
- readFiles(files[index], dataEntryReader);
- }
- }
- }
-}
diff --git a/src/proguard/io/DirectoryWriter.java b/src/proguard/io/DirectoryWriter.java
deleted file mode 100644
index e44e195..0000000
--- a/src/proguard/io/DirectoryWriter.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-
-import java.io.*;
-
-
-/**
- * This DataEntryWriter writes data entries to individual files in a given
- * directory.
- *
- * @author Eric Lafortune
- */
-public class DirectoryWriter implements DataEntryWriter
-{
- private final File baseFile;
- private final boolean isFile;
-
- private File currentFile;
- private OutputStream currentOutputStream;
- private Finisher currentFinisher;
-
-
- /**
- * Creates a new DirectoryWriter.
- * @param baseFile the base directory to which all files will be written.
- */
- public DirectoryWriter(File baseFile,
- boolean isFile)
- {
- this.baseFile = baseFile;
- this.isFile = isFile;
- }
-
-
- // Implementations for DataEntryWriter.
-
- public boolean createDirectory(DataEntry dataEntry) throws IOException
- {
- // Should we close the current file?
- if (!isFile &&
- currentFile != null)
- {
- closeEntry();
- }
-
- File directory = getFile(dataEntry);
- if (!directory.exists() &&
- !directory.mkdirs())
- {
- throw new IOException("Can't create directory [" + directory.getPath() + "]");
- }
-
- return true;
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry, null);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException
- {
- File file = getFile(dataEntry);
-
- // Should we close the current file?
- if (!isFile &&
- currentFile != null &&
- !currentFile.equals(file))
- {
- closeEntry();
- }
-
- // Do we need a new stream?
- if (currentOutputStream == null)
- {
- // Make sure the parent directories exist.
- File parentDirectory = file.getParentFile();
- if (parentDirectory != null &&
- !parentDirectory.exists() &&
- !parentDirectory.mkdirs())
- {
- throw new IOException("Can't create directory [" + parentDirectory.getPath() + "]");
- }
-
- // Open a new output stream for writing to the file.
- currentOutputStream =
- new BufferedOutputStream(
- new FileOutputStream(file));
-
- currentFinisher = finisher;
- currentFile = file;
- }
-
- return currentOutputStream;
- }
-
-
- public void close() throws IOException
- {
- // Close the file stream, if any.
- closeEntry();
- }
-
-
- // Small utility methods.
-
- /**
- * Returns the file for the given data entry.
- */
- private File getFile(DataEntry dataEntry)
- {
- // Use the specified file, or construct a new file.
- return isFile ?
- baseFile :
- new File(baseFile,
- dataEntry.getName().replace(ClassConstants.PACKAGE_SEPARATOR,
- File.separatorChar));
- }
-
-
- /**
- * Closes the previous file, if any.
- */
- private void closeEntry() throws IOException
- {
- // Close the file stream, if any.
- if (currentOutputStream != null)
- {
- // Let any finisher finish up first.
- if (currentFinisher != null)
- {
- currentFinisher.finish();
- currentFinisher = null;
- }
-
- currentOutputStream.close();
- currentOutputStream = null;
- currentFile = null;
- }
- }
-}
diff --git a/src/proguard/io/FileDataEntry.java b/src/proguard/io/FileDataEntry.java
deleted file mode 100644
index f188f3b..0000000
--- a/src/proguard/io/FileDataEntry.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-
-import java.io.*;
-
-/**
- * This <code>DataEntry</code> represents a file.
- *
- * @author Eric Lafortune
- */
-public class FileDataEntry implements DataEntry
-{
- private final File directory;
- private final File file;
- private InputStream inputStream;
-
-
- public FileDataEntry(File directory,
- File file)
- {
- this.directory = directory;
- this.file = file;
- }
-
-
- // Implementations for DataEntry.
-
- public String getName()
- {
- // Chop the directory name from the file name and get the right separators.
- return file.equals(directory) ?
- file.getName() :
- file.getPath()
- .substring(directory.getPath().length() + File.separator.length())
- .replace(File.separatorChar, ClassConstants.PACKAGE_SEPARATOR);
- }
-
-
- public boolean isDirectory()
- {
- return file.isDirectory();
- }
-
-
- public InputStream getInputStream() throws IOException
- {
- if (inputStream == null)
- {
- inputStream = new BufferedInputStream(new FileInputStream(file));
- }
-
- return inputStream;
- }
-
-
- public void closeInputStream() throws IOException
- {
- inputStream.close();
- inputStream = null;
- }
-
-
- public DataEntry getParent()
- {
- return null;
- }
-
-
- // Implementations for Object.
-
- public String toString()
- {
- return getName();
- }
-}
diff --git a/src/proguard/io/FilteredDataEntryReader.java b/src/proguard/io/FilteredDataEntryReader.java
deleted file mode 100644
index ce0f207..0000000
--- a/src/proguard/io/FilteredDataEntryReader.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.IOException;
-
-
-/**
- * This DataEntryReader delegates to one of two other DataEntryReader instances,
- * depending on whether the data entry passes through a given data entry filter
- * or not.
- *
- * @author Eric Lafortune
- */
-public class FilteredDataEntryReader implements DataEntryReader
-{
- private final DataEntryFilter dataEntryFilter;
- private final DataEntryReader acceptedDataEntryReader;
- private final DataEntryReader rejectedDataEntryReader;
-
-
- /**
- * Creates a new FilteredDataEntryReader with only a reader for accepted
- * data entries.
- * @param dataEntryFilter the data entry filter.
- * @param acceptedDataEntryReader the DataEntryReader to which the reading
- * will be delegated if the filter accepts
- * the data entry. May be <code>null</code>.
- */
- public FilteredDataEntryReader(DataEntryFilter dataEntryFilter,
- DataEntryReader acceptedDataEntryReader)
- {
- this(dataEntryFilter, acceptedDataEntryReader, null);
- }
-
-
- /**
- * Creates a new FilteredDataEntryReader.
- * @param dataEntryFilter the data entry filter.
- * @param acceptedDataEntryReader the DataEntryReader to which the reading
- * will be delegated if the filter accepts
- * the data entry. May be <code>null</code>.
- * @param rejectedDataEntryReader the DataEntryReader to which the reading
- * will be delegated if the filter does not
- * accept the data entry. May be
- * <code>null</code>.
- */
- public FilteredDataEntryReader(DataEntryFilter dataEntryFilter,
- DataEntryReader acceptedDataEntryReader,
- DataEntryReader rejectedDataEntryReader)
- {
- this.dataEntryFilter = dataEntryFilter;
- this.acceptedDataEntryReader = acceptedDataEntryReader;
- this.rejectedDataEntryReader = rejectedDataEntryReader;
- }
-
-
- // Implementations for DataEntryReader.
-
- public void read(DataEntry dataEntry)
- throws IOException
- {
- DataEntryReader dataEntryReader = dataEntryFilter.accepts(dataEntry) ?
- acceptedDataEntryReader :
- rejectedDataEntryReader;
-
- if (dataEntryReader != null)
- {
- dataEntryReader.read(dataEntry);
- }
- }
-}
diff --git a/src/proguard/io/FilteredDataEntryWriter.java b/src/proguard/io/FilteredDataEntryWriter.java
deleted file mode 100644
index b8d7977..0000000
--- a/src/proguard/io/FilteredDataEntryWriter.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-/**
- * This DataEntryWriter delegates to one of two other DataEntryWriter instances,
- * depending on whether the data entry passes through a given data entry filter
- * or not.
- *
- * @author Eric Lafortune
- */
-public class FilteredDataEntryWriter implements DataEntryWriter
-{
- private final DataEntryFilter dataEntryFilter;
- private DataEntryWriter acceptedDataEntryWriter;
- private DataEntryWriter rejectedDataEntryWriter;
-
-
- /**
- * Creates a new FilteredDataEntryWriter with only a writer for accepted
- * data entries.
- * @param dataEntryFilter the data entry filter.
- * @param acceptedDataEntryWriter the DataEntryWriter to which the writing
- * will be delegated if the filter accepts
- * the data entry. May be <code>null</code>.
- */
- public FilteredDataEntryWriter(DataEntryFilter dataEntryFilter,
- DataEntryWriter acceptedDataEntryWriter)
- {
- this(dataEntryFilter, acceptedDataEntryWriter, null);
- }
-
-
- /**
- * Creates a new FilteredDataEntryWriter.
- * @param dataEntryFilter the data entry filter.
- * @param acceptedDataEntryWriter the DataEntryWriter to which the writing
- * will be delegated if the filter accepts
- * the data entry. May be <code>null</code>.
- * @param rejectedDataEntryWriter the DataEntryWriter to which the writing
- * will be delegated if the filter does not
- * accept the data entry. May be
- * <code>null</code>.
- */
- public FilteredDataEntryWriter(DataEntryFilter dataEntryFilter,
- DataEntryWriter acceptedDataEntryWriter,
- DataEntryWriter rejectedDataEntryWriter)
- {
- this.dataEntryFilter = dataEntryFilter;
- this.acceptedDataEntryWriter = acceptedDataEntryWriter;
- this.rejectedDataEntryWriter = rejectedDataEntryWriter;
- }
-
-
- // Implementations for DataEntryWriter.
-
- public boolean createDirectory(DataEntry dataEntry) throws IOException
- {
- // Get the right data entry writer.
- DataEntryWriter dataEntryWriter = dataEntryFilter.accepts(dataEntry) ?
- acceptedDataEntryWriter :
- rejectedDataEntryWriter;
-
- // Delegate to it, if it's not null.
- return dataEntryWriter != null &&
- dataEntryWriter.createDirectory(dataEntry);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry, null);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException
- {
- // Get the right data entry writer.
- DataEntryWriter dataEntryWriter = dataEntryFilter.accepts(dataEntry) ?
- acceptedDataEntryWriter :
- rejectedDataEntryWriter;
-
- // Delegate to it, if it's not null.
- return dataEntryWriter != null ?
- dataEntryWriter.getOutputStream(dataEntry, finisher) :
- null;
- }
-
-
- public void close() throws IOException
- {
- if (acceptedDataEntryWriter != null)
- {
- acceptedDataEntryWriter.close();
- acceptedDataEntryWriter = null;
- }
-
- if (rejectedDataEntryWriter != null)
- {
- rejectedDataEntryWriter.close();
- rejectedDataEntryWriter = null;
- }
- }
-}
diff --git a/src/proguard/io/Finisher.java b/src/proguard/io/Finisher.java
deleted file mode 100644
index 74da6f8..0000000
--- a/src/proguard/io/Finisher.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.IOException;
-
-/**
- * This interface specifies a listener that is called to finish an output stream
- * before it is closed.
- *
- * @author Eric Lafortune
- */
-public interface Finisher
-{
- /**
- * Finishes an output stream right before it is closed.
- */
- public void finish() throws IOException;
-}
diff --git a/src/proguard/io/JarReader.java b/src/proguard/io/JarReader.java
deleted file mode 100644
index c4b7e3f..0000000
--- a/src/proguard/io/JarReader.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.IOException;
-import java.util.zip.*;
-
-/**
- * This DataEntryReader lets a given DataEntryReader read all data entries of
- * the read jar/war/zip data entries.
- *
- * @author Eric Lafortune
- */
-public class JarReader implements DataEntryReader
-{
- private final DataEntryReader dataEntryReader;
-
-
- /**
- * Creates a new JarReader.
- */
- public JarReader(DataEntryReader dataEntryReader)
- {
- this.dataEntryReader = dataEntryReader;
- }
-
-
- // Implementation for DataEntryReader.
-
- public void read(DataEntry dataEntry) throws IOException
- {
- ZipInputStream zipInputStream = new ZipInputStream(dataEntry.getInputStream());
-
- try
- {
- // Get all entries from the input jar.
- while (true)
- {
- // Can we get another entry?
- ZipEntry zipEntry = zipInputStream.getNextEntry();
- if (zipEntry == null)
- {
- break;
- }
-
- // Delegate the actual reading to the data entry reader.
- dataEntryReader.read(new ZipDataEntry(dataEntry,
- zipEntry,
- zipInputStream));
- }
- }
- finally
- {
- dataEntry.closeInputStream();
- }
- }
-}
diff --git a/src/proguard/io/JarWriter.java b/src/proguard/io/JarWriter.java
deleted file mode 100644
index 5437f28..0000000
--- a/src/proguard/io/JarWriter.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import java.util.zip.*;
-
-/**
- * This DataEntryWriter sends data entries to a given jar/zip file.
- * The manifest and comment properties can optionally be set.
- *
- * @author Eric Lafortune
- */
-public class JarWriter implements DataEntryWriter, Finisher
-{
- private final DataEntryWriter dataEntryWriter;
- private final Manifest manifest;
- private final String comment;
-
- private OutputStream currentParentOutputStream;
- private ZipOutputStream currentJarOutputStream;
- private Finisher currentFinisher;
- private DataEntry currentDataEntry;
-
- // The names of the jar entries that are already in the jar.
- private final Set jarEntryNames = new HashSet();
-
-
- /**
- * Creates a new JarWriter without manifest or comment.
- */
- public JarWriter(DataEntryWriter dataEntryWriter)
- {
- this(dataEntryWriter, null, null);
- }
-
-
- /**
- * Creates a new JarWriter.
- */
- public JarWriter(DataEntryWriter dataEntryWriter,
- Manifest manifest,
- String comment)
- {
- this.dataEntryWriter = dataEntryWriter;
- this.manifest = manifest;
- this.comment = comment;
- }
-
-
- // Implementations for DataEntryWriter.
-
- public boolean createDirectory(DataEntry dataEntry) throws IOException
- {
- // Make sure we can start with a new entry.
- if (!prepareEntry(dataEntry))
- {
- return false;
- }
-
- // Close the previous ZIP entry, if any.
- closeEntry();
-
- // Get the directory entry name.
- String name = dataEntry.getName() + ClassConstants.PACKAGE_SEPARATOR;
-
- // We have to check if the name is already used, because
- // ZipOutputStream doesn't handle this case properly (it throws
- // an exception which can be caught, but the ZipDataEntry is
- // remembered anyway).
- if (jarEntryNames.add(name))
- {
- // Create a new directory entry.
- currentJarOutputStream.putNextEntry(new ZipEntry(name));
- currentJarOutputStream.closeEntry();
- }
-
- // Clear the finisher.
- currentFinisher = null;
- currentDataEntry = null;
-
- return true;
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry, null);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException
- {
- //Make sure we can start with a new entry.
- if (!prepareEntry(dataEntry))
- {
- return null;
- }
-
- // Do we need a new entry?
- if (!dataEntry.equals(currentDataEntry))
- {
- // Close the previous ZIP entry, if any.
- closeEntry();
-
- // Get the entry name.
- String name = dataEntry.getName();
-
- // We have to check if the name is already used, because
- // ZipOutputStream doesn't handle this case properly (it throws
- // an exception which can be caught, but the ZipDataEntry is
- // remembered anyway).
- if (!jarEntryNames.add(name))
- {
- throw new IOException("Duplicate zip entry ["+dataEntry+"]");
- }
-
- // Create a new entry.
- currentJarOutputStream.putNextEntry(new ZipEntry(name));
-
- // Set up the finisher for the entry.
- currentFinisher = finisher;
- currentDataEntry = dataEntry;
- }
-
- return currentJarOutputStream;
- }
-
-
- public void finish() throws IOException
- {
- // Finish the entire ZIP stream, if any.
- if (currentJarOutputStream != null)
- {
- // Close the previous ZIP entry, if any.
- closeEntry();
-
- // Finish the entire ZIP stream.
- currentJarOutputStream.finish();
- currentJarOutputStream = null;
- currentParentOutputStream = null;
- jarEntryNames.clear();
- }
- }
-
-
- public void close() throws IOException
- {
- // Close the parent stream.
- dataEntryWriter.close();
- }
-
-
- // Small utility methods.
-
- /**
- * Makes sure the current output stream is set up for the given entry.
- */
- private boolean prepareEntry(DataEntry dataEntry) throws IOException
- {
- // Get the parent stream, new or existing.
- // This may finish our own jar output stream.
- OutputStream parentOutputStream =
- dataEntryWriter.getOutputStream(dataEntry.getParent(), this);
-
- // Did we get a stream?
- if (parentOutputStream == null)
- {
- return false;
- }
-
- // Do we need a new stream?
- if (currentParentOutputStream == null)
- {
- currentParentOutputStream = parentOutputStream;
-
- // Create a new jar stream, with a manifest, if set.
- currentJarOutputStream = manifest != null ?
- new JarOutputStream(parentOutputStream, manifest) :
- new ZipOutputStream(parentOutputStream);
-
- // Add a comment, if set.
- if (comment != null)
- {
- currentJarOutputStream.setComment(comment);
- }
- }
-
- return true;
- }
-
-
- /**
- * Closes the previous ZIP entry, if any.
- */
- private void closeEntry() throws IOException
- {
- if (currentDataEntry != null)
- {
- // Let any finisher finish up first.
- if (currentFinisher != null)
- {
- currentFinisher.finish();
- currentFinisher = null;
- }
-
- currentJarOutputStream.closeEntry();
- currentDataEntry = null;
- }
- }
-}
diff --git a/src/proguard/io/ManifestRewriter.java b/src/proguard/io/ManifestRewriter.java
deleted file mode 100644
index f45ad9e..0000000
--- a/src/proguard/io/ManifestRewriter.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassPool;
-
-import java.io.*;
-
-/**
- * This DataEntryReader writes the manifest data entries that it reads to a
- * given DataEntryWriter, updating their contents based on the renamed classes
- * in the given ClassPool.
- *
- * @author Eric Lafortune
- */
-public class ManifestRewriter extends DataEntryRewriter
-{
- /**
- * Creates a new ManifestRewriter.
- */
- public ManifestRewriter(ClassPool classPool,
- DataEntryWriter dataEntryWriter)
- {
- super(classPool, dataEntryWriter);
- }
-
-
- // Implementations for DataEntryRewriter.
-
- protected void copyData(Reader reader,
- Writer writer)
- throws IOException
- {
- super.copyData(new SplitLineReader(reader),
- new SplitLineWriter(writer));
- }
-
-
- /**
- * This Reader reads manifest files, joining any split lines. It replaces
- * the allowed CR/LF/CR+LF alternatives by simple LF in the process.
- */
- private static class SplitLineReader extends FilterReader
- {
- private static final int NONE = -2;
-
- private int bufferedCharacter = NONE;
-
-
- public SplitLineReader(Reader reader)
- {
- super(reader);
- }
-
-
- // Implementations for Reader.
-
- public int read() throws IOException
- {
- while (true)
- {
- // Get the buffered character or the first character.
- int c1 = bufferedCharacter != NONE ?
- bufferedCharacter :
- super.read();
-
- // Clear the buffered character.
- bufferedCharacter = NONE;
-
- // Return it if it's an ordinary character.
- if (c1 != '\n' && c1 != '\r')
- {
- return c1;
- }
-
- // It's a newline. Read the second character to see if it's a
- // continuation.
- int c2 = super.read();
-
- // Skip any corresponding, redundant \n or \r.
- if ((c2 == '\n' || c2 == '\r') && c1 != c2)
- {
- c2 = super.read();
- }
-
- // Isn't it a continuation after all?
- if (c2 != ' ')
- {
- // Buffer the second character and return a newline.
- bufferedCharacter = c2;
- return '\n';
- }
-
- // Just continue after the continuation characters.
- }
- }
-
-
- public int read(char[] cbuf, int off, int len) throws IOException
- {
- // Delegate to reading a single character at a time.
- int count = 0;
- while (count < len)
- {
- int c = read();
- if (c == -1)
- {
- break;
- }
-
- cbuf[off + count++] = (char)c;
- }
-
- return count;
- }
-
-
- public long skip(long n) throws IOException
- {
- // Delegate to reading a single character at a time.
- int count = 0;
- while (count < n)
- {
- int c = read();
- if (c == -1)
- {
- break;
- }
-
- count++;
- }
-
- return count;
- }
- }
-
-
- /**
- * This Writer writes manifest files, splitting any long lines.
- */
- private static class SplitLineWriter extends FilterWriter
- {
- private int counter = 0;
-
-
- public SplitLineWriter(Writer writer)
- {
- super(writer);
- }
-
-
- // Implementations for Reader.
-
- public void write(int c) throws IOException
- {
- // TODO: We should actually count the Utf-8 bytes, not the characters.
- if (c == '\n')
- {
- // Reset the character count.
- counter = 0;
- }
- else if (counter == 70)
- {
- // Insert a newline and a space.
- super.write('\n');
- super.write(' ');
-
- counter = 2;
- }
- else
- {
- counter++;
- }
-
- super.write(c);
- }
-
-
- public void write(char[] cbuf, int off, int len) throws IOException
- {
- for (int count = 0; count < len; count++)
- {
- write(cbuf[off + count]);
- }
- }
-
-
- public void write(String str, int off, int len) throws IOException
- {
- write(str.toCharArray(), off, len);
- }
- }
-} \ No newline at end of file
diff --git a/src/proguard/io/NameFilter.java b/src/proguard/io/NameFilter.java
deleted file mode 100644
index b2e5539..0000000
--- a/src/proguard/io/NameFilter.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.util.*;
-
-import java.util.List;
-
-/**
- * This DataEntryReader delegates to one of two other DataEntryReader instances,
- * depending on the name of the data entry.
- *
- * @author Eric Lafortune
- */
-public class NameFilter extends FilteredDataEntryReader
-{
- /**
- * Creates a new NameFilter that delegates to the given reader, depending
- * on the given list of filters.
- */
- public NameFilter(String regularExpression,
- DataEntryReader acceptedDataEntryReader)
- {
- this(regularExpression, acceptedDataEntryReader, null);
- }
-
-
- /**
- * Creates a new NameFilter that delegates to either of the two given
- * readers, depending on the given list of filters.
- */
- public NameFilter(String regularExpression,
- DataEntryReader acceptedDataEntryReader,
- DataEntryReader rejectedDataEntryReader)
- {
- super(new DataEntryNameFilter(new ListParser(new FileNameParser()).parse(regularExpression)),
- acceptedDataEntryReader,
- rejectedDataEntryReader);
- }
-
-
- /**
- * Creates a new NameFilter that delegates to the given reader, depending
- * on the given list of filters.
- */
- public NameFilter(List regularExpressions,
- DataEntryReader acceptedDataEntryReader)
- {
- this(regularExpressions, acceptedDataEntryReader, null);
- }
-
-
- /**
- * Creates a new NameFilter that delegates to either of the two given
- * readers, depending on the given list of filters.
- */
- public NameFilter(List regularExpressions,
- DataEntryReader acceptedDataEntryReader,
- DataEntryReader rejectedDataEntryReader)
- {
- super(new DataEntryNameFilter(new ListParser(new FileNameParser()).parse(regularExpressions)),
- acceptedDataEntryReader,
- rejectedDataEntryReader);
- }
-} \ No newline at end of file
diff --git a/src/proguard/io/ParentDataEntryWriter.java b/src/proguard/io/ParentDataEntryWriter.java
deleted file mode 100644
index 9f97e46..0000000
--- a/src/proguard/io/ParentDataEntryWriter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-/**
- * This DataEntryWriter lets another DataEntryWriter write the parent data
- * entries.
- *
- * @author Eric Lafortune
- */
-public class ParentDataEntryWriter implements DataEntryWriter
-{
- private DataEntryWriter dataEntryWriter;
-
-
- /**
- * Creates a new ParentDataEntryWriter.
- * @param dataEntryWriter the DataEntryWriter to which the writing will be
- * delegated, passing the data entries' parents.
- */
- public ParentDataEntryWriter(DataEntryWriter dataEntryWriter)
- {
- this.dataEntryWriter = dataEntryWriter;
- }
-
-
- // Implementations for DataEntryWriter.
-
-
- public boolean createDirectory(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry) != null;
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry) throws IOException
- {
- return getOutputStream(dataEntry, null);
- }
-
-
- public OutputStream getOutputStream(DataEntry dataEntry,
- Finisher finisher) throws IOException
- {
- return dataEntryWriter.getOutputStream(dataEntry.getParent(),
- finisher);
- }
-
-
- public void close() throws IOException
- {
- dataEntryWriter.close();
- dataEntryWriter = null;
- }
-}
diff --git a/src/proguard/io/RenamedDataEntry.java b/src/proguard/io/RenamedDataEntry.java
deleted file mode 100644
index ce97b3f..0000000
--- a/src/proguard/io/RenamedDataEntry.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import java.io.*;
-
-/**
- * This DataEntry wraps another data entry, returning a different name instead
- * of the wrapped data entry's name.
- *
- * @author Eric Lafortune
- */
-public class RenamedDataEntry implements DataEntry
-{
- private final DataEntry dataEntry;
- private final String name;
-
-
- public RenamedDataEntry(DataEntry dataEntry,
- String name)
- {
- this.dataEntry = dataEntry;
- this.name = name;
- }
-
-
- // Implementations for DataEntry.
-
- public String getName()
- {
- return name;
- }
-
-
- public boolean isDirectory()
- {
- return dataEntry.isDirectory();
- }
-
-
- public InputStream getInputStream() throws IOException
- {
- return dataEntry.getInputStream();
- }
-
-
- public void closeInputStream() throws IOException
- {
- dataEntry.closeInputStream();
- }
-
-
- public DataEntry getParent()
- {
- return dataEntry.getParent();
- }
-
-
- // Implementations for Object.
-
- public String toString()
- {
- return name + " == " + dataEntry;
- }
-}
diff --git a/src/proguard/io/ZipDataEntry.java b/src/proguard/io/ZipDataEntry.java
deleted file mode 100644
index 84e24db..0000000
--- a/src/proguard/io/ZipDataEntry.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program 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 of the License, or (at your option)
- * any later version.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.io;
-
-import proguard.classfile.ClassConstants;
-
-import java.io.*;
-import java.util.zip.*;
-
-/**
- * This <code>DataEntry</code> represents a ZIP entry.
- *
- * @author Eric Lafortune
- */
-public class ZipDataEntry implements DataEntry
-{
- private final DataEntry parent;
- private final ZipEntry zipEntry;
- private ZipInputStream zipInputStream;
- private InputStream bufferedInputStream;
-
-
- public ZipDataEntry(DataEntry parent,
- ZipEntry zipEntry,
- ZipInputStream zipInputStream)
- {
- this.parent = parent;
- this.zipEntry = zipEntry;
- this.zipInputStream = zipInputStream;
- }
-
-
- // Implementations for DataEntry.
-
- public String getName()
- {
- // Get the right separators.
- String name = zipEntry.getName()
- .replace(File.separatorChar, ClassConstants.PACKAGE_SEPARATOR);
-
- // Chop the trailing directory slash, if any.
- int length = name.length();
- return length > 0 &&
- name.charAt(length-1) == ClassConstants.PACKAGE_SEPARATOR ?
- name.substring(0, length -1) :
- name;
- }
-
-
- public boolean isDirectory()
- {
- return zipEntry.isDirectory();
- }
-
-
- public InputStream getInputStream() throws IOException
- {
- if (bufferedInputStream == null)
- {
- bufferedInputStream = new BufferedInputStream(zipInputStream);
- }
-
- return bufferedInputStream;
- }
-
-
- public void closeInputStream() throws IOException
- {
- zipInputStream.closeEntry();
- zipInputStream = null;
- bufferedInputStream = null;
- }
-
-
- public DataEntry getParent()
- {
- return parent;
- }
-
-
- // Implementations for Object.
-
- public String toString()
- {
- return parent.toString() + ':' + getName();
- }
-}
diff --git a/src/proguard/io/package.html b/src/proguard/io/package.html
deleted file mode 100644
index 4ad9f41..0000000
--- a/src/proguard/io/package.html
+++ /dev/null
@@ -1,4 +0,0 @@
-<body>
-This package contains classes to read and write files, optionally wrapped in
-jars, wars, ears, zips, directories,...
-</body>