protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_hash == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(Hash.HASH_LENGTH); try { _hash.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the hash", dfe); } return os.toByteArray(); }
@Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_gateway == null) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); // flags DataHelper.writeLong(out, 2, 0); out.write(_type); out.write(_cost); DataHelper.writeLong(out, 4, _end.getTime() / 1000); }
@Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeLong(out, 4, _end.getTime() / 1000); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeDate(out, _end); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(256); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 1, _endpoints.size()); for (int i = 0; i < _endpoints.size(); i++) { Hash router = getRouter(i); router.writeBytes(os); TunnelId tunnel = getTunnelId(i); tunnel.writeBytes(os); } DataHelper.writeDate(os, _end); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
peerHash.writeBytes(out);
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(); }
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen); for (int i = 0; i < size; i++) { _leases.get(i).getGateway().writeBytes(baos); _leases.get(i).getTunnelId().writeBytes(baos);
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen); for (int i = 0; i < size; i++) { _leases.get(i).getGateway().writeBytes(baos); _leases.get(i).getTunnelId().writeBytes(baos);
@Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); emailDestHash.writeBytes(dataStream); dataStream.writeShort(entries.size()); for (Entry<Hash, UniqueId> entry: entries.entrySet()) { dataStream.write(entry.getKey().toByteArray()); dataStream.write(entry.getValue().toByteArray()); } } catch (DataFormatException e) { log.error("Invalid format for email destination.", e); } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream.", e); } return byteStream.toByteArray(); }
@Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); destinationHash.writeBytes(dataStream); dataStream.writeInt(entries.size()); for (IndexPacketEntry entry: entries) { dataStream.write(entry.emailPacketKey.toByteArray()); dataStream.write(entry.delVerificationHash.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); // store as seconds } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } catch (DataFormatException e) { log.error("Can't write destination hash to output stream: " + destinationHash, e); } return byteStream.toByteArray(); }