@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(64); try { DataHelper.writeString(os, _reason); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
writeStringUTF8(baos, key); else writeString(baos, key); baos.write('='); if (utf8) writeStringUTF8(baos, val); else writeString(baos, val); baos.write(';');
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_reason == null) throw new DataFormatException("Invalid abuse reason"); DataHelper.writeString(out, _reason); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_version == null) return new byte[0]; ByteArrayOutputStream os = new ByteArrayOutputStream(_options != null ? 128 : 16); try { DataHelper.writeString(os, _version); if (_options != null && !_options.isEmpty()) DataHelper.writeProperties(os, _options, true); // UTF-8 } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_date == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(32); try { DataHelper.writeDate(os, _date); if (_version != null) DataHelper.writeString(os, _version); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
/** * As of 0.9.3, expiration MUST be all zeros as it is ignored on * readin and the signature will fail. */ public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_transportStyle == null) throw new DataFormatException("uninitialized"); out.write((byte) _cost); DataHelper.writeLong(out, 8, _expiration); DataHelper.writeString(out, _transportStyle); DataHelper.writeProperties(out, _options); }
@Test public void testString() throws Exception{ byte[] temp = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataHelper.writeString(baos, "Hello, I2P"); temp = baos.toByteArray(); String s = null; ByteArrayInputStream bais = new ByteArrayInputStream(temp); s = DataHelper.readString(bais); assertEquals(s, "Hello, I2P"); }
protected byte[] doWriteMessage() throws I2CPMessageException, IOException { int len; if (_lookupType == LOOKUP_HASH) { if (_hash == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); len = 11 + Hash.HASH_LENGTH; } else if (_lookupType == LOOKUP_HOST) { if (_host == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); len = 12 + _host.length(); } else { throw new I2CPMessageException("bad type"); } ByteArrayOutputStream os = new ByteArrayOutputStream(len); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 4, _reqID); DataHelper.writeLong(os, 4, _timeout); DataHelper.writeLong(os, 1, _lookupType); if (_lookupType == LOOKUP_HASH) { _hash.writeBytes(os); } else { DataHelper.writeString(os, _host); } } catch (DataFormatException dfe) { throw new I2CPMessageException("bad data", dfe); } return os.toByteArray(); }