Show
Ignore:
Timestamp:
12.12.2016 09:51:07 (3 years ago)
Author:
davidb
Message:

Serialize in and out methods added

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/WhitelistBloomFilter.java

    r31175 r31194  
    22 
    33import java.io.BufferedInputStream; 
     4import java.io.BufferedOutputStream; 
    45import java.io.FileInputStream; 
     6import java.io.FileNotFoundException; 
     7import java.io.FileOutputStream; 
    58import java.io.IOException; 
    69import java.io.InputStream; 
     10import java.io.OutputStream; 
    711import java.nio.charset.StandardCharsets; 
    812import java.nio.file.Files; 
     
    9094        return _bloomFilter.mightContain(key); 
    9195    } 
     96     
     97    public void serializeOut(String filename) 
     98    { 
     99        try { 
     100            FileOutputStream fos = new FileOutputStream(filename); 
     101 
     102            BufferedOutputStream bfos = new BufferedOutputStream(fos); 
     103 
     104            _bloomFilter.writeTo(bfos); 
     105             
     106            bfos.close(); 
     107        } 
     108        catch (FileNotFoundException e) { 
     109            System.err.println("Unable to open Bloom file:" + filename); 
     110            e.printStackTrace(); 
     111        } catch (IOException e) { 
     112            System.err.println("Error reading in Bloom file:" + filename); 
     113            e.printStackTrace(); 
     114        } 
     115    } 
     116     
     117    public void serializeIn(String filename) 
     118    { 
     119        try { 
     120            FileInputStream fis = new FileInputStream(filename); 
     121 
     122            BufferedInputStream bfis = new BufferedInputStream(fis); 
     123 
     124            Funnel<CharSequence> string_funnel = Funnels.stringFunnel(StandardCharsets.UTF_8); 
     125            _bloomFilter = BloomFilter.readFrom(bfis,string_funnel); 
     126             
     127            bfis.close(); 
     128        } 
     129        catch (FileNotFoundException e) { 
     130            System.err.println("Unable to open Bloom file:" + filename); 
     131            e.printStackTrace(); 
     132        } catch (IOException e) { 
     133            System.err.println("Error writing out Bloom file:" + filename); 
     134            e.printStackTrace(); 
     135        } 
     136    } 
     137     
     138     
    92139}