Example usage for org.apache.hadoop.io Text readFields

List of usage examples for org.apache.hadoop.io Text readFields

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text readFields.

Prototype

@Override
public void readFields(DataInput in) throws IOException 

Source Link

Document

deserialize

Usage

From source file:org.goldenorb.io.checkpoint.CheckPointDataTest.java

License:Apache License

/**
 * Tests the CheckPointDataInput class by reading several different types of Writables from the checkpoint.
 * Asserts that Writables that were written in are of the same value and type when reading in from HDFS.
 * // w w w .  j  a v a  2  s  . com
 * @throws Exception
 */
@Test
public void testCheckpointInput() throws Exception {

    int superStep = 0;
    int partition = 0;
    OrbConfiguration orbConf = new OrbConfiguration();
    orbConf.set("fs.default.name", "hdfs://localhost:" + cluster.getNameNodePort());
    orbConf.setJobNumber("0");
    orbConf.setFileOutputPath("test");

    CheckPointDataInput checkpointInput = new CheckPointDataInput(orbConf, superStep, partition);

    // Data is read on a FIFO basis

    IntWritable intInput = new IntWritable();
    intInput.readFields(checkpointInput);

    LongWritable longInput = new LongWritable();
    longInput.readFields(checkpointInput);

    Text textInput = new Text();
    textInput.readFields(checkpointInput);

    FloatWritable floatInput = new FloatWritable();
    floatInput.readFields(checkpointInput);

    checkpointInput.close();

    assertThat(checkpointInput, notNullValue());
    assertEquals(intInput.get(), 4);
    assertEquals(longInput.get(), 9223372036854775807L);
    assertEquals(textInput.toString(), "test");
    assertTrue(floatInput.get() == 3.14159F);
}

From source file:org.goldenorb.zookeeper.ZookeeperUtilsTest.java

License:Apache License

@Test
public void test_writableToByteArray() {
    byte[] byteArray;
    Text testInputText = new Text("this is a test text phrase");
    Text testOutputText = new Text();

    try {/* w w  w .  j a  v a 2  s . co  m*/
        byteArray = ZookeeperUtils.writableToByteArray(testInputText);
        assertNotNull(byteArray);

        ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
        DataInput in = new DataInputStream(bais);
        testOutputText.readFields(in);
        assertEquals(testInputText, testOutputText);
    } catch (IOException e) {
        logger.error("Failed to convert Writable to byte array.");
    }
}

From source file:org.shaf.core.util.IOUtilsTest.java

License:Apache License

/**
 * Test writing of {@code Array} value.//from  ww  w  . ja  va2 s .  com
 */
@Test
public void testWriteArray() {
    byte[] buf = null;

    String[] array = { "h", "e", "l", "l", "o" };
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);) {
        IOUtils.writeObject(array, out);
        buf = baos.toByteArray();
    } catch (IOException exc) {
        fail(exc.getMessage());
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            DataInputStream in = new DataInputStream(bais);) {
        IntWritable len = new IntWritable();
        len.readFields(in);

        String[] probe = new String[len.get()];
        for (int i = 0; i < probe.length; i++) {
            Text text = new Text();
            text.readFields(in);

            probe[i] = text.toString();
        }

        assertArrayEquals(array, probe);
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}

From source file:org.smartfrog.services.hadoop.junitmr.JUnitMRUtils.java

License:Open Source License

static String readText(DataInput in) throws IOException {
    Text t = new Text();
    t.readFields(in);
    String s = t.toString();/*from w  ww . j  a  va  2  s . c  o  m*/
    return s;
}

From source file:org.terrier.structures.serialization.TestFixedSizeTextFactory.java

License:Mozilla Public License

static Text getText(FixedSizeWriteableFactory<Text> factory, byte[] b) throws Exception {
    ByteArrayInputStream buffer = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(buffer);
    Text t = factory.newInstance();
    t.readFields(dis);
    return t;/*from w ww.  j  a  v a  2 s . c om*/
}

From source file:org.zuinnote.hadoop.office.format.common.dao.SpreadSheetCellDAO.java

License:Apache License

@Override
public void readFields(DataInput dataInput) throws IOException {
    Text formattedValueText = (Text) WritableFactories.newInstance(Text.class);
    formattedValueText.readFields(dataInput);
    this.formattedValue = formattedValueText.toString();
    Text commentText = (Text) WritableFactories.newInstance(Text.class);
    commentText.readFields(dataInput);/*from w  w w . j av  a2  s.  c  o m*/
    this.comment = commentText.toString();
    Text formulaText = (Text) WritableFactories.newInstance(Text.class);
    formulaText.readFields(dataInput);
    this.formula = formulaText.toString();
    Text addressText = (Text) WritableFactories.newInstance(Text.class);
    addressText.readFields(dataInput);
    this.address = addressText.toString();
    Text sheetNameText = (Text) WritableFactories.newInstance(Text.class);
    sheetNameText.readFields(dataInput);
    this.sheetName = sheetNameText.toString();
}

From source file:uk.ac.cam.eng.extraction.hadoop.datatypes.TargetFeatureList.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    instance.clear();//from   ww w . j  a v  a  2s  .  c  o  m
    int size = WritableUtils.readVInt(in);
    for (int i = 0; i < size; ++i) {
        Text target = new Text();
        target.readFields(in);
        AlignmentAndFeatureMap alignmentAndFeatures = new AlignmentAndFeatureMap();
        alignmentAndFeatures.readFields(in);
        instance.add(Pair.createPair(target, alignmentAndFeatures));
    }
}