Package proguard.io

Class DexDataEntryWriter

java.lang.Object
proguard.io.DexDataEntryWriter
All Implemented Interfaces:
AutoCloseable, DataEntryWriter
Direct Known Subclasses:
D8BasedDexDataEntryWriter

public abstract class DexDataEntryWriter extends Object implements DataEntryWriter
This DataEntryWriter finds received class entries in the given class pool, collects them in a dex file, and writes it out to the given data entry writer. For resource entries, it returns valid output streams. For class entries, it returns output streams that must not be used.
See Also:
  • Field Details

    • dexFileName

      protected final String dexFileName
    • dexDataEntryWriter

      protected final DataEntryWriter dexDataEntryWriter
    • otherDataEntryWriter

      protected final DataEntryWriter otherDataEntryWriter
  • Constructor Details

    • DexDataEntryWriter

      public DexDataEntryWriter(ClassPool classPool, StringMatcher classNameFilter, String dexFileName, boolean forceDex, DataEntryReader extraDexDataEntryVisitor, DataEntryWriter dexDataEntryWriter, DataEntryWriter otherDataEntryWriter)
      Creates a new DexDataEntryWriter.
      Parameters:
      classPool - the class pool from which classes are collected.
      classNameFilter - an optional filter for classes to be written.
      dexFileName - the dex file name.
      forceDex - specifies whether the dex files should always be written, even if they don't contain any code.
      dexDataEntryWriter - the writer to which the converted dex file is written.
      otherDataEntryWriter - the writer to which other data entries are written.
  • Method Details

    • createDirectory

      public boolean createDirectory(DataEntry dataEntry) throws IOException
      Description copied from interface: DataEntryWriter
      Creates a directory.
      Specified by:
      createDirectory in interface DataEntryWriter
      Parameters:
      dataEntry - the data entry for which the directory is to be created.
      Returns:
      whether the directory has been created.
      Throws:
      IOException
    • sameOutputStream

      public boolean sameOutputStream(DataEntry dataEntry1, DataEntry dataEntry2) throws IOException
      Description copied from interface: DataEntryWriter
      Returns whether the two given data entries would result in the same output stream.
      Specified by:
      sameOutputStream in interface DataEntryWriter
      Parameters:
      dataEntry1 - the first data entry.
      dataEntry2 - the second data entry.
      Throws:
      IOException
    • createOutputStream

      public OutputStream createOutputStream(DataEntry dataEntry) throws IOException
      Description copied from interface: DataEntryWriter
      Creates a new output stream for writing data. The caller is responsible for closing the stream.
      Specified by:
      createOutputStream in interface DataEntryWriter
      Parameters:
      dataEntry - the data entry for which the output stream is to be created.
      Returns:
      the output stream. The stream may be null to indicate that the data entry should not be written.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Description copied from interface: DataEntryWriter
      Finishes writing all data entries.

      Implementations typically create graphs of writers that can split and merge again, possibly even with cycles.

      For splits and merges, implementations need to be idempotent; once closed, subsequent attempts to close a writer have no effect. If needed, the wrapper NonClosingDataEntryWriter can avoid closing a branch prematurely.

      For cycles, implementations must perform any custom behavior, then delegate DataEntryWriter.close() invocations, and only finally clean up. It is possible that delegates call DataEntryWriter.createOutputStream(DataEntry) while DataEntryWriter.close() is in progress.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DataEntryWriter
      Throws:
      IOException
    • println

      public void println(PrintWriter pw, String prefix)
      Description copied from interface: DataEntryWriter
      Prints out the structure of the data entry writer.
      Specified by:
      println in interface DataEntryWriter
      Parameters:
      pw - the print stream to which the structure should be printed.
      prefix - a prefix for every printed line.
    • writeDex

      protected abstract void writeDex(OutputStream outputStream) throws IOException
      Creates a new Dex instance from the collected classes.
      Throws:
      IOException