@Override public Object read(ByteBuffer buff, int tag) { switch (tag) { case TAG_BIG_INTEGER_0: return BigInteger.ZERO; case TAG_BIG_INTEGER_1: return BigInteger.ONE; case TAG_BIG_INTEGER_SMALL: return BigInteger.valueOf(DataUtils.readVarLong(buff)); } int len = DataUtils.readVarInt(buff); byte[] bytes = DataUtils.newBytes(len); buff.get(bytes); return new BigInteger(bytes); }
public SpatialDataType(int dimensions) { // Because of how we are storing the // min-max-flag in the read/write method // the number of dimensions must be < 32. DataUtils.checkArgument(dimensions >= 1 && dimensions < 32, "Dimensions must be between 1 and 31, is {0}", dimensions); this.dimensions = dimensions; }
private void checkOpen() { if (closed) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_CLOSED, "This storage is closed", panicException); } }
static void readCheckValue(ByteBuffer buff, int chunkId, int offset, int pageLength, boolean disableCheck) { short check = buff.getShort(); int checkTest = DataUtils.getCheckValue(chunkId) ^ DataUtils.getCheckValue(offset) ^ DataUtils.getCheckValue(pageLength); if (!disableCheck && check != (short) checkTest) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_FILE_CORRUPT, "File corrupted in chunk {0}, expected check value {1}, got {2}", chunkId, checkTest, check); } }
/** * Create a new IllegalArgumentException. * * @param message the message * @param arguments the arguments * @return the exception */ public static IllegalArgumentException newIllegalArgumentException(String message, Object... arguments) { return initCause(new IllegalArgumentException(formatMessage(0, message, arguments)), arguments); }
case 0: int len = DataUtils.readVarInt(idBuffer); idBuffer.position(idBuffer.position() + len); length += len; case 1: length += DataUtils.readVarInt(idBuffer); DataUtils.readVarLong(idBuffer); break; case 2: length += DataUtils.readVarLong(idBuffer); DataUtils.readVarLong(idBuffer); break; default: throw DataUtils.newIllegalArgumentException("Unsupported id {0}", Arrays.toString(id));
@Override public Object read(ByteBuffer buff) { int flags = DataUtils.readVarInt(buff); if (flags == -1) { long id = DataUtils.readVarLong(buff); return new SpatialKey(id); } float[] minMax = new float[dimensions * 2]; for (int i = 0; i < dimensions; i++) { float min = buff.getFloat(); float max; if ((flags & (1 << i)) != 0) { max = min; } else { max = buff.getFloat(); } minMax[i + i] = min; minMax[i + i + 1] = max; } long id = DataUtils.readVarLong(buff); return new SpatialKey(id, minMax); }
byte[] data; int len = tag - TAG_BYTE_ARRAY_0_15; data = DataUtils.newBytes(len); buff.get(data); return data; clazz = Class.forName(componentType); } catch (Exception e) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_SERIALIZATION, "Could not get class {0}", componentType, e); clazz = ObjectDataType.COMMON_CLASSES[ct]; int len = DataUtils.readVarInt(buff); try { obj = Array.newInstance(clazz, len); } catch (Exception e) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_SERIALIZATION, "Could not create array of type {0} length {1}", clazz, len, e);
private static int readVarInt(ByteBuffer buff) { return DataUtils.readVarInt(buff); }
@Override public Object read(ByteBuffer buff, int tag) { int len = DataUtils.readVarInt(buff); byte[] data = DataUtils.newBytes(len); buff.get(data); return deserialize(data); }
private static long readVarLong(ByteBuffer buff) { return DataUtils.readVarLong(buff); }
@Override public void remove() { throw DataUtils.newUnsupportedOperationException("Removing is not supported"); } };
/** * This method is called before writing to the map. * The default implementation checks whether writing is allowed. * * @throws UnsupportedOperationException if the map is read-only. */ protected void beforeWrite() { if (btreeStorage.isClosed()) { throw DataUtils.newIllegalStateException(DataUtils.ERROR_CLOSED, "This map is closed"); } if (readOnly) { throw DataUtils.newUnsupportedOperationException("This map is read-only"); } }
@Override public Value readValue(ByteBuffer buff, int tag) { int len; if (tag == STRING) { len = DataUtils.readVarInt(buff); if (len == 0) return ValueNull.INSTANCE; } else { len = tag - TAG_STRING_0_15; } return ValueString.get(DataUtils.readString(buff, len)); } };
FilePath parent = f.getParent(); if (parent != null && !parent.exists()) { throw DataUtils.newIllegalArgumentException("Directory does not exist: {0}", parent); throw DataUtils.newIllegalStateException(DataUtils.ERROR_FILE_LOCKED, "The file is locked: {0}", fileName, e); throw DataUtils.newIllegalStateException(DataUtils.ERROR_FILE_LOCKED, "The file is locked: {0}", fileName); throw DataUtils.newIllegalStateException(DataUtils.ERROR_READING_FAILED, "Could not open file {0}", fileName, e);
DataUtils.writeVarInt(id, len); id.write(buff); } else { DataUtils.writeVarInt(id, len); DataUtils.writeVarLong(id, writeBlock(buff));
/** * Throw an IllegalArgumentException if the argument is invalid. * * @param test true if the argument is valid * @param message the message * @param arguments the arguments * @throws IllegalArgumentException if the argument is invalid */ public static void checkArgument(boolean test, String message, Object... arguments) { if (!test) { throw newIllegalArgumentException(message, arguments); } }
public StringBuilder asStringBuilder() { StringBuilder buff = new StringBuilder(); DataUtils.appendMap(buff, "id", id); DataUtils.appendMap(buff, "rootPagePos", rootPagePos); DataUtils.appendMap(buff, "blockCount", blockCount); DataUtils.appendMap(buff, "pageCount", pageCount); DataUtils.appendMap(buff, "sumOfPageLength", sumOfPageLength); DataUtils.appendMap(buff, "pagePositionsOffset", pagePositionsOffset); DataUtils.appendMap(buff, "pageLengthsOffset", pageLengthsOffset); DataUtils.appendMap(buff, "blockSize", BTreeStorage.BLOCK_SIZE); DataUtils.appendMap(buff, "format", FORMAT_VERSION); return buff; }
private synchronized void writeChunkHeader(BTreeChunk chunk) { StringBuilder buff = chunk.asStringBuilder(); byte[] bytes = buff.toString().getBytes(DataUtils.LATIN); int checksum = DataUtils.getFletcher32(bytes, bytes.length); DataUtils.appendMap(buff, "fletcher", checksum); buff.append("\n"); bytes = buff.toString().getBytes(DataUtils.LATIN); ByteBuffer header = ByteBuffer.allocate(CHUNK_HEADER_SIZE); header.put(bytes); header.position(BLOCK_SIZE); header.put(bytes); header.rewind(); write(chunk.fileStorage, 0, header); }