@Override protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException { if (size > 0) { try { _version = DataHelper.readString(in); if (size > 1 + _version.length()) // assume ascii _options = DataHelper.readProperties(in); } catch (DataFormatException dfe) { throw new I2CPMessageException("Bad version string", dfe); } } }
/** Read a mapping from the stream, as defined by the I2P data structure spec, * and store it into a Properties object. * * A mapping is a set of key / value pairs. It starts with a 2 byte Integer (ala readLong(rawStream, 2)) * defining how many bytes make up the mapping. After that comes that many bytes making * up a set of UTF-8 encoded characters. The characters are organized as key=value;. * The key is a String (ala readString(rawStream)) unique as a key within the current * mapping that does not include the UTF-8 characters '=' or ';'. After the key * comes the literal UTF-8 character '='. After that comes a String (ala readString(rawStream)) * for the value. Finally after that comes the literal UTF-8 character ';'. This key=value; * is repeated until there are no more bytes (not characters!) left as defined by the * first two byte integer. * * As of 0.9.18, throws DataFormatException on duplicate key * * @param rawStream stream to read the mapping from * @throws DataFormatException if the format is invalid * @throws IOException if there is a problem reading the data * @return an OrderedProperties */ public static Properties readProperties(InputStream rawStream) throws DataFormatException, IOException { Properties props = new OrderedProperties(); readProperties(rawStream, props); return props; }
/** * As of 0.9.3, expiration MUST be all zeros as it is ignored on * readin and the signature will fail. * Restored as of 0.9.12, wait several more releases before using. * @throws IllegalStateException if was already read in */ public void readBytes(InputStream in) throws DataFormatException, IOException { if (_transportStyle != null) throw new IllegalStateException(); // EOF will be thrown in next read _cost = (short) in.read(); _expiration = DataHelper.readLong(in, 8); _transportStyle = DataHelper.readString(in); // reduce Object proliferation if (_transportStyle.equals("SSU")) _transportStyle = "SSU"; else if (_transportStyle.equals("NTCP")) _transportStyle = "NTCP"; else if (_transportStyle.equals("NTCP2")) _transportStyle = "NTCP2"; DataHelper.readProperties(in, _options); }
/** returns null on error */ public DestEntry construct(byte[] b) { DestEntry rv = new DestEntry(); ByteArrayInputStream bais = new ByteArrayInputStream(b); try { rv.props = DataHelper.readProperties(bais); //dest.readBytes(bais); // Will this flush the dest cache too much? rv.dest = Destination.create(bais); } catch (IOException ioe) { logError("DB Read Fail", ioe); return null; } catch (DataFormatException dfe) { logError("DB Read Fail", dfe); return null; } return rv; } }
@Test public void testProperties() throws Exception{ byte[] temp = null; Properties orig = new Properties(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); orig.setProperty("key1", "val1"); orig.setProperty("key2", "val2"); orig.setProperty("key3", "val3"); DataHelper.writeProperties(baos, orig); temp = baos.toByteArray(); Properties p = null; ByteArrayInputStream bais = new ByteArrayInputStream(temp); p = DataHelper.readProperties(bais); assertEquals(orig, p); } }
public void readBytes(InputStream rawConfig) throws DataFormatException, IOException { _destination = Destination.create(rawConfig); _options = DataHelper.readProperties(rawConfig); _creationDate = DataHelper.readDate(rawConfig); _signature = new Signature(_destination.getSigningPublicKey().getType()); _signature.readBytes(rawConfig); }
_options = DataHelper.readProperties(in, null); int numLeases = in.read();
DataHelper.readProperties(din, _options); _signature = new Signature(type); _signature.readBytes(in);
_options = DataHelper.readProperties(in, null); int numKeys = in.read(); if (numKeys <= 0 || numKeys > MAX_KEYS)