public static String readString( ReadableChannel channel, int length ) throws IOException { assert length >= 0 : "invalid array length " + length; byte[] chars = new byte[length]; channel.get( chars, length ); return UTF8.decode( chars ); }
private Command visitRelationshipCountsCommand( ReadableChannel channel ) throws IOException { int startLabelId = channel.getInt(); int typeId = channel.getInt(); int endLabelId = channel.getInt(); long delta = channel.getLong(); return new Command.RelationshipCountsCommand( startLabelId, typeId, endLabelId, delta ); }
private Object readIndexValue( byte valueType, ReadableChannel channel ) throws IOException { switch ( valueType ) { case IndexCommand.VALUE_TYPE_NULL: return null; case IndexCommand.VALUE_TYPE_SHORT: return channel.getShort(); case IndexCommand.VALUE_TYPE_INT: return channel.getInt(); case IndexCommand.VALUE_TYPE_LONG: return channel.getLong(); case IndexCommand.VALUE_TYPE_FLOAT: return channel.getFloat(); case IndexCommand.VALUE_TYPE_DOUBLE: return channel.getDouble(); case IndexCommand.VALUE_TYPE_STRING: return read3bLengthAndString( channel ); default: throw new RuntimeException( "Unknown value type " + valueType ); } } }
public static String read3bLengthAndString( ReadableChannel channel ) throws IOException { short lengthShort = channel.getShort(); byte lengthByte = channel.get(); int length = (lengthByte << 16) | (lengthShort & 0xFFFF); byte[] chars = new byte[length]; channel.get( chars, length ); return UTF8.decode( chars ); }
private Command visitRelationshipGroupCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); byte inUseByte = channel.get(); boolean inUse = inUseByte == Record.IN_USE.byteValue(); if ( inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseByte ); } int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); return new Command.RelationshipGroupCommand( null, record ); }
private DynamicRecord readDynamicRecord( ReadableChannel channel ) throws IOException { // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long) long id = channel.getLong(); assert id >= 0 && id <= (1L << 36) - 1 : id + " is not a valid dynamic record id"; int type = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0; DynamicRecord record = new DynamicRecord( id ); record.setInUse( inUse, type ); if ( inUse ) { record.setStartRecord( (inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0 ); int nrOfBytes = channel.getInt(); assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1) : nrOfBytes + " is not valid for a number of bytes field of " + "a dynamic record"; long nextBlock = channel.getLong(); assert (nextBlock >= 0 && nextBlock <= (1L << 36 - 1)) || (nextBlock == Record.NO_NEXT_BLOCK.intValue()) : nextBlock + " is not valid for a next record field of " + "a dynamic record"; record.setNextBlock( nextBlock ); byte[] data = new byte[nrOfBytes]; channel.get( data, nrOfBytes ); record.setData( data ); } return record; }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return new Command.PropertyKeyTokenCommand( null, record ); }
private long[] readLongs( ReadableChannel channel, int count ) throws IOException { long[] result = new long[count]; for ( int i = 0; i < count; i++ ) { result[i] = channel.getLong(); } return result; }
private static void dumpPrepare( Dumper dumper, byte type, ReadableChannel channel, long range, int labelId, TxFilter txFilter, long session, long flush ) throws IOException { long txId = channel.getLong(); int offset = channel.get(); long nodeId = range * 64 + offset; if ( txFilter == null || txFilter.contains( txId ) ) { // I.e. if the txId this update comes from is within the txFilter dumper.prepare( type == TYPE_PREPARE_ADD, session, flush, txId, nodeId, labelId ); } }
private <T> int readDynamicRecords( ReadableChannel channel, T target, DynamicRecordAdder<T> adder ) throws IOException { int numberOfRecords = channel.getInt(); assert numberOfRecords >= 0; while ( numberOfRecords > 0 ) { DynamicRecord read = readDynamicRecord( channel ); if ( read == null ) { return -1; } adder.add( target, read ); numberOfRecords--; } return numberOfRecords; }
private int getUnsignedShort( ReadableChannel channel ) throws IOException { int result = channel.getShort() & 0xFFFF; return result == 0xFFFF ? -1 : result; }
private Command visitRelationshipGroupCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); byte inUseByte = channel.get(); boolean inUse = inUseByte == Record.IN_USE.byteValue(); if ( inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseByte ); } int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); return new Command.RelationshipGroupCommand( null, record ); }
private DynamicRecord readDynamicRecord( ReadableChannel channel ) throws IOException { // id+type+in_use(byte)+nr_of_bytes(int)+next_block(long) long id = channel.getLong(); assert id >= 0 && id <= (1L << 36) - 1 : id + " is not a valid dynamic record id"; int type = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = (inUseFlag & Record.IN_USE.byteValue()) != 0; DynamicRecord record = new DynamicRecord( id ); record.setInUse( inUse, type ); if ( inUse ) { record.setStartRecord( (inUseFlag & Record.FIRST_IN_CHAIN.byteValue()) != 0 ); int nrOfBytes = channel.getInt(); assert nrOfBytes >= 0 && nrOfBytes < ((1 << 24) - 1) : nrOfBytes + " is not valid for a number of bytes field of " + "a dynamic record"; long nextBlock = channel.getLong(); assert (nextBlock >= 0 && nextBlock <= (1L << 36 - 1)) || (nextBlock == Record.NO_NEXT_BLOCK.intValue()) : nextBlock + " is not valid for a next record field of " + "a dynamic record"; record.setNextBlock( nextBlock ); byte[] data = new byte[nrOfBytes]; channel.get( data, nrOfBytes ); record.setData( data ); } return record; }
private Command visitPropertyKeyTokenCommand( ReadableChannel channel ) throws IOException { // id+in_use(byte)+count(int)+key_blockId(int) int id = channel.getInt(); byte inUseFlag = channel.get(); boolean inUse = false; if ( (inUseFlag & Record.IN_USE.byteValue()) == Record.IN_USE.byteValue() ) { inUse = true; } else if ( inUseFlag != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseFlag ); } PropertyKeyTokenRecord record = new PropertyKeyTokenRecord( id ); record.setInUse( inUse ); record.setPropertyCount( channel.getInt() ); record.setNameId( channel.getInt() ); if ( readDynamicRecords( channel, record, PROPERTY_INDEX_DYNAMIC_RECORD_ADDER ) == -1 ) { return null; } return new Command.PropertyKeyTokenCommand( null, record ); }
private long[] readLongs( ReadableChannel channel, int count ) throws IOException { long[] result = new long[count]; for ( int i = 0; i < count; i++ ) { result[i] = channel.getLong(); } return result; }
private NodeRecord readNodeRecord( long id, ReadableChannel channel ) throws IOException byte inUseFlag = channel.get(); boolean inUse = false; if ( inUseFlag == Record.IN_USE.byteValue() ) if ( inUse ) boolean dense = channel.get() == 1; record = new NodeRecord( id, dense, channel.getLong(), channel.getLong() ); labelField = channel.getLong();
private <T> int readDynamicRecords( ReadableChannel channel, T target, DynamicRecordAdder<T> adder ) throws IOException { int numberOfRecords = channel.getInt(); assert numberOfRecords >= 0; while ( numberOfRecords > 0 ) { DynamicRecord read = readDynamicRecord( channel ); if ( read == null ) { return -1; } adder.add( target, read ); numberOfRecords--; } return numberOfRecords; }
public static String read3bLengthAndString( ReadableChannel channel ) throws IOException { short lengthShort = channel.getShort(); byte lengthByte = channel.get(); int length = (lengthByte << 16) | (lengthShort & 0xFFFF); byte[] chars = new byte[length]; channel.get( chars, length ); return UTF8.decode( chars ); }
private int getUnsignedShort( ReadableChannel channel ) throws IOException { int result = channel.getShort() & 0xFFFF; return result == 0xFFFF ? -1 : result; }
private Command visitRelationshipCountsCommand( ReadableChannel channel ) throws IOException { int startLabelId = channel.getInt(); int typeId = channel.getInt(); int endLabelId = channel.getInt(); long delta = channel.getLong(); return new Command.RelationshipCountsCommand( startLabelId, typeId, endLabelId, delta ); }