@Override public void readFully(byte[] b) throws IOException { readFully(b, 0, b.length); }
@Override public byte[] deserialize(DataInput2 in, int available) throws IOException { byte[] ret = new byte[16]; in.readFully(ret); return ret; }
@Override public byte[] deserialize(DataInput2 in, int available) throws IOException { byte[] ret = new byte[available]; in.readFully(ret); return ret; }
@Override public byte[] deserialize(DataInput2 in, int available) throws IOException { byte[] ret = new byte[HashFunctionPool.hashLength]; in.readFully(ret); return ret; }
ByteArrayKeys(DataInput2 in, int[] offsets, int prefixLen) throws IOException { this.offset = offsets; array = new byte[offsets[offsets.length-1]]; in.readFully(array, 0, prefixLen); for(int i=0; i<offsets.length-1;i++){ System.arraycopy(array,0,array,offsets[i],prefixLen); } //$DELAY$ //read suffixes int offset = prefixLen; for(int o:offsets){ in.readFully(array,offset,o-offset); offset = o+prefixLen; } }
@Override public String deserialize(DataInput2 in, int available) throws IOException { if (available == -1) throw new IllegalArgumentException("STRING_NOSIZE does not work with collections."); byte[] bytes = new byte[available]; in.readFully(bytes); return new String(bytes, UTF8_CHARSET); }
@Override public byte[] deserialize(DataInput2 in, int available) throws IOException { int size = in.unpackInt(); byte[] ret = new byte[size]; in.readFully(ret); return ret; }
@Override public ObjectId deserialize(@NotNull DataInput2 input, int available) throws IOException { final byte[] raw = new byte[fixedSize()]; input.readFully(raw); return ObjectId.fromRaw(raw); } };
@Override public byte[][] valueArrayDeserialize(DataInput2 in, int size) throws IOException { byte[][] ret = new byte[size][]; //read lengths and init arrays for(int i=0;i<ret.length;i++){ ret[i] = new byte[in.unpackInt()]; } //$DELAY$ //read and distribute common prefix int prefixLen = in.unpackInt(); in.readFully(ret[0],0,prefixLen); for(int i=1;i<ret.length;i++){ System.arraycopy(ret[0],0,ret[i],0,prefixLen); } //$DELAY$ //read suffixes for (byte[] aRet : ret) { in.readFully(aRet, prefixLen, aRet.length - prefixLen); } return ret; }
@Override public T deserialize(@NotNull DataInput2 input, int available) throws IOException { int classIdx = input.readInt(); String className = getClassForInt(classIdx); Class<?> clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new RuntimeException(e); //Shouldn't normally happen... } Persistable p; try { p = (Persistable) clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } int remainingLength = available - 4; //-4 for int class index byte[] temp = new byte[remainingLength]; input.readFully(temp); p.decode(temp); return (T) p; }
@Override public ByteArrayKeys valueArrayDeserialize(DataInput2 in, int size) throws IOException { //read data sizes int[] offsets = new int[size]; int old=0; for(int i=0;i<size;i++){ old+= in.unpackInt(); offsets[i]=old; } byte[] bb = new byte[old]; //$DELAY$ //read and distribute common prefix int prefixLen = in.unpackInt(); in.readFully(bb, 0, prefixLen); for(int i=0; i<offsets.length-1;i++){ System.arraycopy(bb, 0, bb, offsets[i], prefixLen); } //$DELAY$ //read suffixes int offset = prefixLen; for(int o:offsets){ in.readFully(bb,offset,o-offset); offset = o+prefixLen; } return new ByteArrayKeys(offsets,bb); }
/** * Transfers data from this Volume into target volume. * If its possible, the implementation should override this method to enable direct memory transfer. * * Caller must respect slice boundaries. ie it is not possible to transfer data which cross slice boundaries. * * @param inputOffset offset inside this Volume, ie data will be read from this offset * @param target Volume to copy data into * @param targetOffset position in target volume where data will be copied into * @param size size of data to copy */ public void copyTo(long inputOffset, Volume target, long targetOffset, long size) { //TODO size>Integer.MAX_VALUE byte[] data = new byte[(int) size]; try { getDataInput(inputOffset, (int) size).readFully(data); }catch(IOException e){ throw new DBException.VolumeIOError(e); } target.putData(targetOffset,data,0, (int) size); }
private PartitionedEvent readPartitionedEvent(DataInput2 in) throws IOException { PartitionedEvent event = new PartitionedEvent(); event.setPartitionKey(in.unpackLong()); int partitionHashCode = in.unpackInt(); if (partitionHashCode != 0 && hashCodePartitionDict.containsKey(partitionHashCode)) { event.setPartition(hashCodePartitionDict.get(partitionHashCode)); } int eventBytesLen = in.unpackInt(); if (eventBytesLen > 0) { byte[] eventBytes = new byte[eventBytesLen]; in.readFully(eventBytes); event.setEvent((StreamEvent) SerializableUtils.deserializeFromCompressedByteArray(eventBytes, "Deserialize event from bytes")); } return event; }