/** * Merges name/attribute pairs read from the input stream {@code is} into this manifest. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the manifest. */ public void read(InputStream is) throws IOException { byte[] buf; if (is instanceof ByteArrayInputStream) { buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is); } else { buf = Streams.readFullyNoClose(is); } if (buf.length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.length - 1]; if (b == 0 || b == 26) { buf[buf.length - 1] = '\n'; } ManifestReader im = new ManifestReader(buf, mainAttributes); mainEnd = im.getEndOfMainSection(); im.readEntries(entries, chunks); }
public ManifestReader(byte[] buf, Attributes main) throws IOException { this.buf = buf; while (readHeader()) { main.put(name, value); } this.endOfMainSection = pos; }
/** * Read a single line from the manifest buffer. */ private boolean readHeader() throws IOException { if (consecutiveLineBreaks > 1) { // break a section on an empty line consecutiveLineBreaks = 0; return false; } readName(); consecutiveLineBreaks = 0; readValue(); // if the last line break is missed, the line // is ignored by the reference implementation return consecutiveLineBreaks > 0; }
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;
/** * Merges name/attribute pairs read from the input stream {@code is} into this manifest. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the manifest. */ public void read(InputStream is) throws IOException { byte[] buf; if (is instanceof ByteArrayInputStream) { buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is); } else { buf = Streams.readFullyNoClose(is); } if (buf.length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.length - 1]; if (b == 0 || b == 26) { buf[buf.length - 1] = '\n'; } ManifestReader im = new ManifestReader(buf, mainAttributes); mainEnd = im.getEndOfMainSection(); im.readEntries(entries, chunks); }
/** * Read a single line from the manifest buffer. */ private boolean readHeader() throws IOException { if (consecutiveLineBreaks > 1) { // break a section on an empty line consecutiveLineBreaks = 0; return false; } readName(); consecutiveLineBreaks = 0; readValue(); // if the last line break is missed, the line // is ignored by the reference implementation return consecutiveLineBreaks > 0; }
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;
public void readEntries(Map<String, Attributes> entries, Map<String, Manifest.Chunk> chunks) throws IOException { int mark = pos; while (readHeader()) { if (!Attributes.Name.NAME.equals(name)) { throw new IOException("Entry is not named"); } String entryNameValue = value; Attributes entry = entries.get(entryNameValue); if (entry == null) { entry = new Attributes(12); } while (readHeader()) { entry.put(name, value); } if (chunks != null) { if (chunks.get(entryNameValue) != null) { // TODO A bug: there might be several verification chunks for // the same name. I believe they should be used to update // signature in order of appearance; there are two ways to fix // this: either use a list of chunks, or decide on used // signature algorithm in advance and reread the chunks while // updating the signature; for now a defensive error is thrown throw new IOException("A jar verifier does not support more than one entry with the same name"); } chunks.put(entryNameValue, new Manifest.Chunk(mark, pos)); mark = pos; } entries.put(entryNameValue, entry); } }
/** * Merges name/attribute pairs read from the input stream {@code is} into this manifest. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the manifest. */ public void read(InputStream is) throws IOException { byte[] buf; if (is instanceof ByteArrayInputStream) { buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is); } else { buf = Streams.readFullyNoClose(is); } if (buf.length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.length - 1]; if (b == 0 || b == 26) { buf[buf.length - 1] = '\n'; } ManifestReader im = new ManifestReader(buf, mainAttributes); mainEnd = im.getEndOfMainSection(); im.readEntries(entries, chunks); }
/** * Read a single line from the manifest buffer. */ private boolean readHeader() throws IOException { if (consecutiveLineBreaks > 1) { // break a section on an empty line consecutiveLineBreaks = 0; return false; } readName(); consecutiveLineBreaks = 0; readValue(); // if the last line break is missed, the line // is ignored by the reference implementation return consecutiveLineBreaks > 0; }
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;
public ManifestReader(byte[] buf, Attributes main) throws IOException { this.buf = buf; while (readHeader()) { main.put(name, value); } this.endOfMainSection = pos; }
/** * Merges name/attribute pairs read from the input stream {@code is} into this manifest. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the manifest. */ public void read(InputStream is) throws IOException { byte[] buf; if (is instanceof ByteArrayInputStream) { buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is); } else { buf = Streams.readFullyNoClose(is); } if (buf.length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.length - 1]; if (b == 0 || b == 26) { buf[buf.length - 1] = '\n'; } ManifestReader im = new ManifestReader(buf, mainAttributes); mainEnd = im.getEndOfMainSection(); im.readEntries(entries, chunks); }
/** * Read a single line from the manifest buffer. */ private boolean readHeader() throws IOException { if (consecutiveLineBreaks > 1) { // break a section on an empty line consecutiveLineBreaks = 0; return false; } readName(); consecutiveLineBreaks = 0; readValue(); // if the last line break is missed, the line // is ignored by the reference implementation return consecutiveLineBreaks > 0; }
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;
public ManifestReader(byte[] buf, Attributes main) throws IOException { this.buf = buf; while (readHeader()) { main.put(name, value); } this.endOfMainSection = pos; }
/** * Merges name/attribute pairs read from the input stream {@code is} into this manifest. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the manifest. */ public void read(InputStream is) throws IOException { byte[] buf; if (is instanceof ByteArrayInputStream) { buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is); } else { buf = Streams.readFullyNoClose(is); } if (buf.length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.length - 1]; if (b == 0 || b == 26) { buf[buf.length - 1] = '\n'; } ManifestReader im = new ManifestReader(buf, mainAttributes); mainEnd = im.getEndOfMainSection(); im.readEntries(entries, chunks); }
/** * Read a single line from the manifest buffer. */ private boolean readHeader() throws IOException { if (consecutiveLineBreaks > 1) { // break a section on an empty line consecutiveLineBreaks = 0; return false; } readName(); consecutiveLineBreaks = 0; readValue(); // if the last line break is missed, the line // is ignored by the reference implementation return consecutiveLineBreaks > 0; }
HashMap<String, Attributes> entries = new HashMap<String, Attributes>(); try { ManifestReader im = new ManifestReader(sfBytes, attributes); im.readEntries(entries, null); } catch (IOException e) { return;