private void initFromEncodedBytes() throws IOException { DataByteArrayInputStream inputStream = new DataByteArrayInputStream(encodedXidBytes); inputStream.skipBytes(10); formatId = inputStream.readInt(); int globalLength = inputStream.readShort(); globalTransactionId = new byte[globalLength]; try { inputStream.read(globalTransactionId); branchQualifier = new byte[inputStream.available()]; inputStream.read(branchQualifier); } catch (IOException fatal) { throw new RuntimeException(this + ", failed to decode:", fatal); } }
try (DataByteArrayInputStream controlIs = new DataByteArrayInputStream(bs)) { if (controlIs.readByte() != BATCH_CONTROL_RECORD_HEADER[i]) { return -1; int size = controlIs.readInt(); if (size < 0 || size > Integer.MAX_VALUE - (BATCH_CONTROL_RECORD_SIZE + EOF_RECORD.length)) { return -2; long expectedChecksum = controlIs.readLong(); Checksum checksum = null; if (isChecksum() && expectedChecksum > 0) { bs.setOffset(controlIs.position()); int toRead = size; while (toRead > 0) {
@Override public synchronized Object unmarshal(ByteSequence sequence) throws IOException { bytesIn.restart(sequence); // DataInputStream dis = new DataInputStream(new // ByteArrayInputStream(sequence)); if (!sizePrefixDisabled) { int size = bytesIn.readInt(); if (sequence.getLength() - 4 != size) { // throw new IOException("Packet size does not match marshaled // size"); } if (size > maxFrameSize) { throw IOExceptionSupport.createFrameSizeException(size, maxFrameSize); } } Object command = doUnmarshal(bytesIn); // if( !cacheEnabled && ((DataStructure)command).isMarshallAware() ) { // ((MarshallAware) command).setCachedMarshalledForm(this, sequence); // } return command; }
public static Properties stringToProperties(String str) throws IOException { Properties result = new Properties(); if (str != null && str.length() > 0) { DataByteArrayInputStream dataIn = new DataByteArrayInputStream(str.getBytes()); result.load(dataIn); dataIn.close(); } return result; }
private void stringFormArj(StringBuffer s, byte[] uid) { try { DataByteArrayInputStream byteArrayInputStream = new DataByteArrayInputStream(uid); s.append(Long.toString(byteArrayInputStream.readLong(), 16)); s.append(':'); s.append(Long.toString(byteArrayInputStream.readLong(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); } catch (Exception ignored) { stringFormDefault(s, uid); } }
/** * Loads a previously stored JournalMessage * * @param location * @return * @throws IOException */ public JournalCommand<?> load(Location location) throws IOException { long start = System.currentTimeMillis(); ByteSequence data = journal.read(location); long end = System.currentTimeMillis(); if( LOG_SLOW_ACCESS_TIME>0 && end-start > LOG_SLOW_ACCESS_TIME) { if (LOG.isInfoEnabled()) { LOG.info("Slow KahaDB access: Journal read took: "+(end-start)+" ms"); } } DataByteArrayInputStream is = new DataByteArrayInputStream(data); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if( type == null ) { try { is.close(); } catch (IOException e) {} throw new IOException("Could not load journal record, null type information from: " + readByte + " at location: "+location); } JournalCommand<?> message = (JournalCommand<?>)type.createMessage(); message.mergeFramed(is); return message; }
public void recoverLastAck(byte[] encodedXid, final ActiveMQDestination destination, final String subName, final String clientId) throws IOException { Tx tx = getPreparedTx(new XATransactionId(encodedXid)); DataByteArrayInputStream inputStream = new DataByteArrayInputStream(encodedXid); inputStream.skipBytes(1); // +|- final long lastAck = inputStream.readLong(); final byte priority = inputStream.readByte(); final MessageAck ack = new MessageAck(); ack.setDestination(destination);
public JournalCommand<?> load(Location location) throws IOException { DataByteArrayInputStream is = new DataByteArrayInputStream(journal.read(location)); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>) type.createMessage(); message.mergeFramed(is); return message; }
/** * re-start the input stream - reusing the current buffer * * @param size */ public void restart(int size) { if (buf == null || buf.length < size) { buf = new byte[size]; } restart(buf); }
public void load() { if (loaded.compareAndSet(false, true)) { keysPerPage = pageSize / keySize; dataIn = new DataByteArrayInputStream(); dataOut = new DataByteArrayOutputStream(pageSize); readBuffer = new byte[pageSize]; indexFile.seek(offset); indexFile.readFully(readBuffer, 0, TreePage.PAGE_HEADER_SIZE); dataIn.restart(readBuffer); TreePage page = new TreePage(keysPerPage); page.setTree(this);
public void readFully(byte[] b, int off, int len) { read(b, off, len); }
OpenWireWriteStream(OpenWireTransport transport, OpenWireFormat wireFormat) { this.transport = transport; this.wireFormat = wireFormat; this.dataIn = new DataByteArrayInputStream(); }
public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
public String readUTF() throws IOException { int length = readUnsignedShort(); if (pos + length > buf.length) { throw new UTFDataFormatException("bad string"); } char chararr[] = new char[length]; String result = MarshallingSupport.convertUTF8WithBuf(buf, chararr, pos, length); pos += length; return result; } }
/** * Loads a previously stored JournalMessage * * @param location * The location of the journal command to read. * * @return a new un-marshaled JournalCommand instance. * * @throws IOException if an error occurs reading the stored command. */ protected JournalCommand<?> load(Location location) throws IOException { ByteSequence data = journal.read(location); DataByteArrayInputStream is = new DataByteArrayInputStream(data); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { try { is.close(); } catch (IOException e) { } throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>)type.createMessage(); message.mergeFramed(is); return message; }
public void recoverLastAck(byte[] encodedXid, final ActiveMQDestination destination, final String subName, final String clientId) throws IOException { Tx tx = getPreparedTx(new XATransactionId(encodedXid)); DataByteArrayInputStream inputStream = new DataByteArrayInputStream(encodedXid); inputStream.skipBytes(1); // +|- final long lastAck = inputStream.readLong(); final byte priority = inputStream.readByte(); final MessageAck ack = new MessageAck(); ack.setDestination(destination);
private void stringFormArj(StringBuffer s, byte[] uid) { try { DataByteArrayInputStream byteArrayInputStream = new DataByteArrayInputStream(uid); s.append(Long.toString(byteArrayInputStream.readLong(), 16)); s.append(':'); s.append(Long.toString(byteArrayInputStream.readLong(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); s.append(':'); s.append(Integer.toString(byteArrayInputStream.readInt(), 16)); } catch (Exception ignored) { stringFormDefault(s, uid); } }
public static Properties stringToProperties(String str) throws IOException { Properties result = new Properties(); if (str != null && str.length() > 0) { DataByteArrayInputStream dataIn = new DataByteArrayInputStream(str.getBytes()); result.load(dataIn); dataIn.close(); } return result; }
public JournalCommand<?> load(Location location) throws IOException { DataByteArrayInputStream is = new DataByteArrayInputStream(journal.read(location)); byte readByte = is.readByte(); KahaEntryType type = KahaEntryType.valueOf(readByte); if (type == null) { throw new IOException("Could not load journal record. Invalid location: " + location); } JournalCommand<?> message = (JournalCommand<?>) type.createMessage(); message.mergeFramed(is); return message; }