/** Writes the pools content to the given {@link DataOutput} */ public final void writePool(final DataOutput out) throws IOException { int bytesOffset = byteOffset; int block = 0; while (bytesOffset > 0) { out.writeBytes(buffers[block++], BYTE_BLOCK_SIZE); bytesOffset -= BYTE_BLOCK_SIZE; } out.writeBytes(buffers[block], byteUpto); }
/** * Serializes the data set to file using the following format: * * <ul> * <li>FuzzySet -->FuzzySetVersion,HashFunctionName,BloomSize, * NumBitSetWords,BitSetWord<sup>NumBitSetWords</sup> * <li>HashFunctionName --> {@link DataOutput#writeString(String) String} The name of a * ServiceProvider registered {@link HashFunction} * <li>FuzzySetVersion --> {@link DataOutput#writeInt Uint32} The version number of the * {@link FuzzySet} class * <li>BloomSize --> {@link DataOutput#writeInt Uint32} The modulo value used to project * hashes into the field's Bitset * <li>NumBitSetWords --> {@link DataOutput#writeInt Uint32} The number of longs (as returned * from {@link FixedBitSet#getBits}) * <li>BitSetWord --> {@link DataOutput#writeLong Long} A long from the array returned by * {@link FixedBitSet#getBits} * </ul> * * @param out Data output stream * @throws IOException If there is a low-level I/O error */ public void serialize(DataOutput out) throws IOException { out.writeInt(VERSION_CURRENT); out.writeInt(bloomSize); long[] bits = filter.getBits(); out.writeInt(bits.length); for (int i = 0; i < bits.length; i++) { // Can't used VLong encoding because cant cope with negative numbers // output by FixedBitSet out.writeLong(bits[i]); } }
public long writeTo(DataOutput out) throws IOException { long size = 0; while (true) { if (limit + bufferOffset == endIndex) { assert endIndex - bufferOffset >= upto; out.writeBytes(buffer, upto, limit - upto); size += limit - upto; break; } else { out.writeBytes(buffer, upto, limit - upto); size += limit - upto; nextSlice(); } } return size; }
private void writeRecursively(DataOutput out, TSTNode node) throws IOException { if (node == null) { return; } out.writeString(new String(new char[] {node.splitchar}, 0, 1)); byte mask = 0; if (node.relatives[TSTNode.LOKID] != null) mask |= LO_KID; if (node.relatives[TSTNode.EQKID] != null) mask |= EQ_KID; if (node.relatives[TSTNode.HIKID] != null) mask |= HI_KID; if (node.data != null) mask |= HAS_VALUE; out.writeByte(mask); if (node.data != null) { out.writeLong(((Number) node.data).longValue()); } writeRecursively(out, node.relatives[TSTNode.LOKID]); writeRecursively(out, node.relatives[TSTNode.EQKID]); writeRecursively(out, node.relatives[TSTNode.HIKID]); }
@Override public boolean store(DataOutput output) throws IOException { output.writeVLong(count); TSTNode root = trie.getRoot(); if (root == null) { // empty tree return false; } writeRecursively(output, root); return true; }
// pre-order traversal private void writeRecursively(DataOutput out, TernaryTreeNode node) throws IOException { // write out the current node out.writeString(new String(new char[] {node.splitchar}, 0, 1)); // prepare a mask of kids byte mask = 0; if (node.eqKid != null) mask |= EQ_KID; if (node.loKid != null) mask |= LO_KID; if (node.hiKid != null) mask |= HI_KID; if (node.token != null) mask |= HAS_TOKEN; if (node.val != null) mask |= HAS_VALUE; out.writeByte(mask); if (node.token != null) out.writeString(node.token); if (node.val != null) out.writeLong(((Number) node.val).longValue()); // recurse and write kids if (node.loKid != null) { writeRecursively(out, node.loKid); } if (node.eqKid != null) { writeRecursively(out, node.eqKid); } if (node.hiKid != null) { writeRecursively(out, node.hiKid); } }
@Override public synchronized boolean store(DataOutput output) throws IOException { output.writeVLong(count); writeRecursively(output, root); return true; }
@Override public void write(Long output, DataOutput out) throws IOException { assert valid(output); out.writeVLong(output); }