Package aQute.lib.manifest
Class ManifestUtil
- java.lang.Object
-
- aQute.lib.manifest.ManifestUtil
-
public final class ManifestUtil extends java.lang.ObjectUnfortunately 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 Summary
Fields Modifier and Type Field Description private static byte[]EOLprivate static intMAX_LENGTHprivate static java.util.jar.Attributes.NameNAMEprivate static java.util.Comparator<java.util.jar.Attributes.Name>nameComparatorprivate static byte[]SEPARATOR
-
Constructor Summary
Constructors Modifier Constructor Description privateManifestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.util.Map<java.util.jar.Attributes.Name,java.lang.String>coerce(java.util.jar.Attributes attributes)Coerce Attributes to Map. private static java.util.stream.Stream<java.util.Map.Entry<java.util.jar.Attributes.Name,java.lang.String>>sortedAttributes(java.util.jar.Attributes attributes)Sort the attributes by key.private static intwrite(java.io.OutputStream out, int width, byte[] bytes)Write the bytes but ensure that the line length does not exceed 72 characters.private static intwrite(java.io.OutputStream out, int width, java.lang.String s)Convert a string to bytes with UTF-8 and then output in max 72 bytesstatic voidwrite(java.util.jar.Manifest manifest, java.io.OutputStream out)private static voidwriteAttributes(java.io.OutputStream out, java.util.stream.Stream<java.util.Map.Entry<java.util.jar.Attributes.Name,java.lang.String>> attributes)Output an Attributes map.private static voidwriteEntry(java.io.OutputStream out, java.util.jar.Attributes.Name name, java.lang.String value)Write out an entry, handling proper unicode and line length constraints
-
-
-
Field Detail
-
nameComparator
private static final java.util.Comparator<java.util.jar.Attributes.Name> nameComparator
-
NAME
private static final java.util.jar.Attributes.Name NAME
-
EOL
private static final byte[] EOL
-
SEPARATOR
private static final byte[] SEPARATOR
-
MAX_LENGTH
private static final int MAX_LENGTH
-
-
Method Detail
-
write
public static void write(java.util.jar.Manifest manifest, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeEntry
private static void writeEntry(java.io.OutputStream out, java.util.jar.Attributes.Name name, java.lang.String value) throws java.io.IOExceptionWrite out an entry, handling proper unicode and line length constraints- Throws:
java.io.IOException
-
write
private static int write(java.io.OutputStream out, int width, java.lang.String s) throws java.io.IOExceptionConvert a string to bytes with UTF-8 and then output in max 72 bytes- Parameters:
out- the output stringwidth- the current widths- the string to output- Returns:
- the new width
- Throws:
java.io.IOException- when something fails
-
write
private static int write(java.io.OutputStream out, int width, byte[] bytes) throws java.io.IOExceptionWrite 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 streamwidth- The number of characters output in a line before this method startedbytes- the bytes to output- Returns:
- the number of characters in the last line
- Throws:
java.io.IOException- if something fails
-
writeAttributes
private static void writeAttributes(java.io.OutputStream out, java.util.stream.Stream<java.util.Map.Entry<java.util.jar.Attributes.Name,java.lang.String>> attributes) throws java.io.IOExceptionOutput an Attributes map. We sort the map keys.- Parameters:
value- the attributesout- the output stream- Throws:
java.io.IOException- when something fails
-
sortedAttributes
private static java.util.stream.Stream<java.util.Map.Entry<java.util.jar.Attributes.Name,java.lang.String>> sortedAttributes(java.util.jar.Attributes attributes)
Sort the attributes by key.- Parameters:
attributes- the attributes- Throws:
A- sorted stream of the attributes
-
coerce
private static java.util.Map<java.util.jar.Attributes.Name,java.lang.String> coerce(java.util.jar.Attributes attributes)
Coerce Attributes to Map. - Parameters:
attribute- the attribute- Returns:
- A map.
-
-