List of usage examples for com.google.common.hash BloomFilter readFrom
@CheckReturnValue public static <T> BloomFilter<T> readFrom(InputStream in, Funnel<T> funnel) throws IOException
From source file:org.bboxdb.storage.BloomFilterBuilder.java
/** * Load a persistent bloom filter into memory * @param file// ww w .j a v a 2 s.c o m * @return * @throws IOException */ public static BloomFilter<String> loadBloomFilterFromFile(final File file) throws IOException { try (final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));) { return BloomFilter.readFrom(inputStream, new TupleKeyFunnel()); } catch (IOException e) { throw e; } }
From source file:google.registry.model.translators.BloomFilterOfStringTranslatorFactory.java
@Override public Translator<BloomFilter<String>> create(Path path, Property property, Type type, CreateContext ctx) { if (!BloomFilter.class.equals(erase(type))) { return null; // Skip me and try to find another matching translator }/* w ww. ja v a 2 s . c o m*/ Type fieldBloomFilterType = getTypeParameter(type, BloomFilter.class.getTypeParameters()[0]); if (fieldBloomFilterType == null) { return null; // No type information is available } if (!TypeToken.of(String.class).getType().equals(fieldBloomFilterType)) { return null; // We can only handle BloomFilters of CharSequences } return new ValueTranslator<BloomFilter<String>, Blob>(path, Blob.class) { @Override @Nullable protected BloomFilter<String> loadValue(Blob value, LoadContext ctx) { if (value == null) { return null; } try { @SuppressWarnings("unchecked") Funnel<String> castedFunnel = (Funnel<String>) (Funnel<?>) unencodedCharsFunnel(); return BloomFilter.readFrom(new ByteArrayInputStream(value.getBytes()), castedFunnel); } catch (IOException e) { throw new IllegalStateException("Error loading bloom filter data", e); } } @Override @Nullable protected Blob saveValue(BloomFilter<String> value, SaveContext ctx) { if (value == null) { return null; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { value.writeTo(bos); } catch (IOException e) { throw new IllegalStateException("Error saving bloom filter data", e); } return new Blob(bos.toByteArray()); } }; }
From source file:cc.gospy.core.util.bloomfilter.ScalableBloomFilter.java
public void readFromFile(String dir) throws IOException { File file;/*from w w w . j a v a2s. c om*/ int p = 0; while ((file = new File(dir, this.getClass().getTypeName() + "$" + p + ".tmp")).exists()) { logger.info("Reading bloom remover data ${} from file {}...", p, file.getPath()); FileInputStream inputStream = new FileInputStream(file); this.bloomFilters.clear(); bloomFilters.add(activateBloomFilter = BloomFilter.readFrom(inputStream, Task.DIGEST)); p++; } logger.info("Bloom remover data [$0-${}] is successfully loaded.", groupSize() - 1); }
From source file:org.veronicadb.core.memorygraph.VSubGraph.java
/** * Re-initialize bloomfilter from bytes//www. j a v a 2 s . c om * @param bloomBytes * @throws IOException */ protected void loadBloom(byte[] bloomBytes) throws IOException { subGraphBloom = BloomFilter.readFrom(new ByteArrayInputStream(bloomBytes), Funnels.longFunnel()); }