private static byte[] createEmptyBatchControlRecordHeader() { try (DataByteArrayOutputStream os = new DataByteArrayOutputStream();) { os.writeInt(BATCH_CONTROL_RECORD_SIZE); os.writeByte(BATCH_CONTROL_RECORD_TYPE); os.write(BATCH_CONTROL_RECORD_MAGIC); os.writeInt(0); os.writeLong(0l); ByteSequence sequence = os.toByteSequence(); sequence.compact(); return sequence.getData(); } catch (IOException e) { throw new RuntimeException("Could not create empty batch control record header.", e); } }
public synchronized byte[] getEncodedXidBytes() { if (encodedXidBytes == null) { outputStream = new DataByteArrayOutputStream(XID_PREFIX_SIZE + globalTransactionId.length + branchQualifier.length); outputStream.position(10); outputStream.writeInt(formatId); // global length outputStream.writeShort(globalTransactionId.length); try { outputStream.write(globalTransactionId); outputStream.write(branchQualifier); } catch (IOException fatal) { throw new RuntimeException(this + ", failed to encode:", fatal); } encodedXidBytes = outputStream.getData(); } return encodedXidBytes; }
size += bs.marshalledSize(); bytesOut.restart(size); if (!sizePrefixDisabled) { bytesOut.writeInt(size); bytesOut.writeByte(type); bs.marshal(bytesOut); dsm.tightMarshal2(this, c, bytesOut, bs); sequence = bytesOut.toByteSequence(); bytesOut.restart(); if (!sizePrefixDisabled) { bytesOut.writeInt(0); // we don't know the final size bytesOut.writeByte(type); dsm.looseMarshal(this, c, bytesOut); sequence = bytesOut.toByteSequence(); bytesOut.restart(5); bytesOut.writeInt(size); bytesOut.writeByte(NULL_TYPE); sequence = bytesOut.toByteSequence();
public static String propertiesToString(Properties props) throws IOException { String result = ""; if (props != null) { DataByteArrayOutputStream dataOut = new DataByteArrayOutputStream(); props.store(dataOut, ""); result = new String(dataOut.getData(), 0, dataOut.size()); dataOut.close(); } return result; }
public ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }
private Buffer createBuffer(Object command) { Buffer buffer = null; if (command != null) { try { wireFormat.marshal(command, dataOut); dataOut.flush(); int size = dataOut.size(); byte[] data = new byte[size]; System.arraycopy(dataOut.getData(), 0, data, 0, size); if (size > StompTransport.COMPACT_SIZE) { dataOut.restart(); } dataOut.reset(); buffer = new Buffer(data); } catch (Throwable t) { transport.handleException(t); } } return buffer; }
public synchronized void updateItem(DataItem item, Marshaller marshaller, Object payload, byte type) throws IOException { // Write the packet our internal buffer. buffer.reset(); buffer.position(DataManagerImpl.ITEM_HEAD_SIZE); marshaller.writePayload(payload, buffer); int size = buffer.size(); int payloadSize = size - DataManagerImpl.ITEM_HEAD_SIZE; buffer.reset(); buffer.writeByte(type); buffer.writeInt(payloadSize); item.setSize(payloadSize); DataFile dataFile = dataManager.getDataFile(item); RandomAccessFile file = dataFile.getRandomAccessFile(); file.seek(item.getOffset()); file.write(buffer.getData(), 0, size); dataFile.setWriterData(Boolean.TRUE); // Use as dirty marker.. }
private byte[] encodeXid(XATransactionId xid, long seq, long priority) { byte[] xidVal = xid.getEncodedXidBytes(); // encode the update DataByteArrayOutputStream outputStream = xid.internalOutputStream(); outputStream.position(1); outputStream.writeLong(seq); outputStream.writeByte(Long.valueOf(priority).byteValue()); return xidVal; }
DataByteArrayOutputStream out = new DataByteArrayOutputStream(pageSize); page.write(out); write(page, out.getData());
bytesOut.restart(); looseOut = bytesOut; ByteSequence sequence = bytesOut.toByteSequence(); dataOut.writeInt(sequence.getLength()); dataOut.write(sequence.getData(), sequence.getOffset(), sequence.getLength());
keysPerPage = pageSize / keySize; dataIn = new DataByteArrayInputStream(); dataOut = new DataByteArrayOutputStream(pageSize); readBuffer = new byte[pageSize]; try { lastFree.setNextFreePageId(offset); indexFile.seek(lastFree.getId()); dataOut.reset(); lastFree.writeHeader(dataOut); indexFile.write(dataOut.getData(), 0, TreePage.PAGE_HEADER_SIZE); lastFree = page; } else {
void writeFullPage(HashPage page) throws IOException { dataOut.reset(); page.write(keyMarshaller, dataOut); if (dataOut.size() > pageSize) { throw new IOException("Page Size overflow: pageSize is " + pageSize + " trying to write " + dataOut.size()); } indexFile.seek(page.getId()); indexFile.write(dataOut.getData(), 0, dataOut.size()); }
public void updateItem(StoreLocation location, Marshaller marshaller, Object payload) throws IOException { final DataByteArrayOutputStream buffer = new DataByteArrayOutputStream(); marshaller.writePayload(payload, buffer); ByteSequence data = buffer.toByteSequence(); dataManager.update(convertFromStoreLocation(location), data, false); }
StompReadStream(StompTransport transport, final StompWireFormat wireFormat) { this.transport = transport; this.wireFormat = wireFormat; dataOut = new DataByteArrayOutputStream(); lock = new ReentrantLock(); }
/** * start using a fresh byte array */ public void restart() { restart(DEFAULT_SIZE); }
public void writeDouble(double v) throws IOException { writeLong(Double.doubleToLongBits(v)); }
public void writeFloat(float v) throws IOException { writeInt(Float.floatToIntBits(v)); }
/** * Creates a new ByteSequence that represents the marshaled form of the given Journal Command. * * @param command * The Journal Command that should be marshaled to bytes for writing. * * @return the byte representation of the given journal command. * * @throws IOException if an error occurs while serializing the command. */ protected ByteSequence toByteSequence(JournalCommand<?> data) throws IOException { int size = data.serializedSizeFramed(); DataByteArrayOutputStream os = new DataByteArrayOutputStream(size + 1); os.writeByte(data.type().getNumber()); data.writeFramed(os); return os.toByteSequence(); }