Class ManifestUtil

java.lang.Object
aQute.lib.manifest.ManifestUtil

public final class ManifestUtil extends Object
Unfortunately we have to write our own manifest :-( because of a stupid bug in the manifest code. It tries to handle UTF-8 but the way it does it it makes the bytes platform dependent. So the following code outputs the manifest. A Manifest consists of
 'Manifest-Version: 1.0\r\n'
 main-attributes * \r\n name-section
 main-attributes ::= attributes
 attributes ::= key ': ' value '\r\n'
 name-section ::= 'Name: ' name '\r\n' attributes
 
Lines in the manifest should not exceed 72 bytes (! this is where the manifest screwed up as well when 16 bit unicodes were used).

As a bonus, we can now sort the manifest!

  • Field Details

    • nameComparator

      private static final Comparator<Attributes.Name> nameComparator
    • NAME

      private static final Attributes.Name NAME
    • EOL

      private static final byte[] EOL
    • SEPARATOR

      private static final byte[] SEPARATOR
    • MAX_LENGTH

      private static final int MAX_LENGTH
  • Constructor Details

    • ManifestUtil

      private ManifestUtil()
  • Method Details

    • write

      public static void write(Manifest manifest, OutputStream out) throws IOException
      Throws:
      IOException
    • writeEntry

      private static void writeEntry(OutputStream out, Attributes.Name name, String value) throws IOException
      Write out an entry, handling proper unicode and line length constraints
      Throws:
      IOException
    • write

      private static int write(OutputStream out, int width, String s) throws IOException
      Convert a string to bytes with UTF-8 and then output in max 72 bytes
      Parameters:
      out - the output string
      width - the current width
      s - the string to output
      Returns:
      the new width
      Throws:
      IOException - when something fails
    • write

      private static int write(OutputStream out, int width, byte[] bytes) throws IOException
      Write the bytes but ensure that the line length does not exceed 72 characters. If it is more than 70 characters, we just put a cr/lf + space.
      Parameters:
      out - The output stream
      width - The number of characters output in a line before this method started
      bytes - the bytes to output
      Returns:
      the number of characters in the last line
      Throws:
      IOException - if something fails
    • writeAttributes

      private static void writeAttributes(OutputStream out, Stream<Map.Entry<Attributes.Name,String>> attributes) throws IOException
      Output an Attributes map. We sort the map keys.
      Parameters:
      value - the attributes
      out - the output stream
      Throws:
      IOException - when something fails
    • sortedAttributes

      private static Stream<Map.Entry<Attributes.Name,String>> sortedAttributes(Attributes attributes)
      Sort the attributes by key.
      Parameters:
      attributes - the attributes
      Throws:
      A - sorted stream of the attributes
    • coerce

      private static Map<Attributes.Name,String> coerce(Attributes attributes)
      Coerce Attributes to Map<Name,String>.
      Parameters:
      attribute - the attribute
      Returns:
      A map.