Search in sources :

Example 56 with DataInputStream

use of java.io.DataInputStream in project Cloud9 by lintool.

the class AnchorTextTest method testClone.

@Test
public void testClone() {
    AnchorText anchor1 = new AnchorText(AnchorTextConstants.Type.EXTERNAL_OUT_LINK.val, "text", 1);
    AnchorText anchor2 = anchor1.clone();
    anchor2.setText("some text");
    assertTrue(anchor2.equals(anchor1));
    anchor2.addDocument(2);
    assertNull(anchor2.getText());
    assertEquals(anchor2.getSize(), 2);
    assertTrue(anchor2.equalsIgnoreSources(anchor1));
    AnchorText anchor3 = new AnchorText(AnchorTextConstants.Type.DOCNO_FIELD.val, "text");
    anchor3.addDocumentsFrom(anchor2);
    anchor3.addDocument(2);
    assertNull(anchor3.getText());
    assertEquals(anchor3.getSize(), 2);
    anchor3.setWeight(1);
    assertEquals(anchor3.getWeight(), 0, 1e-100);
    assertEquals(anchor3.compareTo(anchor2), 1);
    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bstream);
    try {
        anchor3.write(out);
        out.close();
    } catch (Exception e) {
    }
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bstream.toByteArray()));
    AnchorText readAnchor = new AnchorText();
    try {
        readAnchor.readFields(in);
        in.close();
    } catch (Exception e) {
    }
    assertEquals(anchor3, readAnchor);
    assertTrue(anchor3.intersects(anchor2));
    assertTrue(anchor3.containsDocument(2));
    anchor3.resetToType(AnchorTextConstants.Type.IN_DEGREE.val);
    assertNull(anchor3.getText());
    anchor3.resetToType(AnchorTextConstants.Type.INTERNAL_IN_LINK.val);
    assertEquals(anchor3.getText(), AnchorTextConstants.EMPTY_STRING);
    assertTrue(anchor3.isInternalInLink());
    assertEquals(anchor3.getSize(), 0);
    assertEquals(anchor3.getWeight(), 0, 1e-100);
    assertFalse(anchor3.containsDocument(3));
    assertFalse(anchor3.intersects(anchor2));
}
Also used : AnchorText(edu.umd.cloud9.webgraph.data.AnchorText) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 57 with DataInputStream

use of java.io.DataInputStream in project Cloud9 by lintool.

the class PhrasePairTest method testWrite.

public void testWrite() {
    try {
        File temp = File.createTempFile("phrpr", null);
        temp.deleteOnExit();
        DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
        pp.write(dos);
        pp2.write(dos);
        PhrasePair px = new PhrasePair(pp.getF(), pp.getE());
        px.write(dos);
        System.out.println(pp.toString(vf, ve));
        System.out.println(pp2.toString(vf, ve));
        System.out.println(px.toString(vf, ve));
        dos.close();
        System.err.println("Size of PPs on disk: " + dos.size());
        DataInputStream dis = new DataInputStream(new FileInputStream(temp));
        PhrasePair pl = new PhrasePair();
        pl.readFields(dis);
        assertEquals(pp.toString(vf, ve), pl.toString(vf, ve));
        assertTrue(pl.equals(pp));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught " + e);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 58 with DataInputStream

use of java.io.DataInputStream in project Cloud9 by lintool.

the class VocabularyWritableTest method testReadFields.

public void testReadFields() {
    try {
        File temp = File.createTempFile("phrpr", null);
        temp.deleteOnExit();
        DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
        v.write(dos);
        dos.close();
        System.err.println("Size of voc on disk: " + dos.size());
        DataInputStream dis = new DataInputStream(new FileInputStream(temp));
        VocabularyWritable vw = new VocabularyWritable();
        vw.readFields(dis);
        assertEquals(v.get(bar), vw.get(bar));
        dis.close();
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught " + e);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 59 with DataInputStream

use of java.io.DataInputStream in project Cloud9 by lintool.

the class IndexedFloatArrayTest method testReadFields.

public void testReadFields() {
    try {
        File temp = File.createTempFile("fat", null);
        temp.deleteOnExit();
        DataOutputStream dos = new DataOutputStream(new FileOutputStream(temp));
        int[] i = { 1, 4, 8, 9, 10 };
        IndexedFloatArray fa = new IndexedFloatArray(i);
        IndexedFloatArray fa2 = new IndexedFloatArray(10);
        fa.set(1, 0.5f);
        fa.set(10, 1.0f);
        fa.add(8, 0.1f);
        fa.add(8, 0.4f);
        fa2.set(4, 2.0f);
        fa.write(dos);
        fa2.write(dos);
        dos.close();
        DataInputStream dis = new DataInputStream(new FileInputStream(temp));
        fa2 = new IndexedFloatArray();
        IndexedFloatArray fa3 = new IndexedFloatArray();
        fa2.readFields(dis);
        fa3.readFields(dis);
        assertEquals(0.5f, fa2.get(1));
        assertEquals(0.5f, fa2.get(8));
        assertEquals(1.0f, fa2.get(10));
        System.err.println(fa2);
        assertEquals(2.0f, fa3.get(4));
    } catch (IOException e) {
        fail("Caught " + e);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 60 with DataInputStream

use of java.io.DataInputStream in project Cloud9 by lintool.

the class HadoopAlign method loadVocab.

public static Vocab loadVocab(Path path, Configuration job) throws IOException {
    org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(job);
    FileSystem fileSys = FileSystem.get(conf);
    DataInput in = new DataInputStream(new BufferedInputStream(fileSys.open(path)));
    VocabularyWritable at = new VocabularyWritable();
    at.readFields(in);
    return at;
}
Also used : DataInput(java.io.DataInput) Configuration(org.apache.hadoop.conf.Configuration) BufferedInputStream(java.io.BufferedInputStream) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) VocabularyWritable(edu.umd.hooka.VocabularyWritable) DataInputStream(java.io.DataInputStream)

Aggregations

DataInputStream (java.io.DataInputStream)1544 ByteArrayInputStream (java.io.ByteArrayInputStream)635 IOException (java.io.IOException)582 DataOutputStream (java.io.DataOutputStream)315 FileInputStream (java.io.FileInputStream)313 Test (org.junit.Test)274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)198 BufferedInputStream (java.io.BufferedInputStream)157 File (java.io.File)151 DataInput (java.io.DataInput)112 InputStream (java.io.InputStream)109 EOFException (java.io.EOFException)90 ArrayList (java.util.ArrayList)90 FileNotFoundException (java.io.FileNotFoundException)88 FileOutputStream (java.io.FileOutputStream)52 InputStreamReader (java.io.InputStreamReader)52 BufferedReader (java.io.BufferedReader)50 Socket (java.net.Socket)44 ByteBuffer (java.nio.ByteBuffer)40 HashMap (java.util.HashMap)38