Example usage for org.apache.hadoop.io IntWritable write

List of usage examples for org.apache.hadoop.io IntWritable write

Introduction

In this page you can find the example usage for org.apache.hadoop.io IntWritable write.

Prototype

@Override
    public void write(DataOutput out) throws IOException 

Source Link

Usage

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

License:Apache License

/**
 * Tests the CheckPointDataOutput class by writing several different types of Writables to the checkpoint.
 * // w w  w.j  ava2 s  .  c  om
 * @throws Exception
 */
@Test
public void testCheckpointOutput() 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");

    CheckPointDataOutput checkpointOutput = new CheckPointDataOutput(orbConf, superStep, partition);

    IntWritable intOutput = new IntWritable(4);
    intOutput.write(checkpointOutput);

    LongWritable longOutput = new LongWritable(9223372036854775807L);
    longOutput.write(checkpointOutput);

    Text textOutput = new Text("test");
    textOutput.write(checkpointOutput);

    FloatWritable floatOutput = new FloatWritable(3.14159F);
    floatOutput.write(checkpointOutput);

    checkpointOutput.close();

    assertThat(checkpointOutput, notNullValue());
}

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

License:Apache License

/**
 * Test reading of {@code Array} value.//w  w  w. j  av a 2s.  c o  m
 */
@Test
public void testReadArray() {
    byte[] buf = null;

    String[] array = { "h", "e", "l", "l", "o" };
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);) {
        IntWritable len = new IntWritable(array.length);
        len.write(out);

        for (String value : array) {
            Text.writeString(out, value);
        }

        buf = baos.toByteArray();
    } catch (IOException exc) {
        fail(exc.getMessage());
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            DataInputStream in = new DataInputStream(bais);) {
        assertArrayEquals(array, (String[]) IOUtils.readObject(String[].class, in));
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}

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

License:Apache License

/**
 * Test reading of {@code Enum} value./*from  ww  w  . j a  va  2 s. co m*/
 */
@Test
public void testReadEnum() {
    byte[] buf = null;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(baos);) {
        IntWritable type = new IntWritable(ActionType.MAP.ordinal());
        type.write(out);

        buf = baos.toByteArray();
    } catch (IOException exc) {
        fail(exc.getMessage());
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            DataInputStream in = new DataInputStream(bais);) {
        assertEquals(ActionType.MAP, (ActionType) IOUtils.readObject(ActionType.class, in));
    } catch (IOException exc) {
        fail(exc.getMessage());
    }
}

From source file:tlfetl.card.TLFDWHValue.java

@Override
public void write(DataOutput d) throws IOException {
    FloatWritable writableAmount = new FloatWritable(amount);
    IntWritable writableCount = new IntWritable(count);
    writableAmount.write(d);//w w w .  j  ava 2  s  . c  o m
    writableCount.write(d);
}

From source file:twitterpagerank.SortedPageRank.java

@Override
public void write(DataOutput d) throws IOException {
    IntWritable size = new IntWritable(priorityQueue.size());
    size.write(d);
    PageRankItem[] a = new PageRankItem[priorityQueue.size()];
    for (PageRankItem e : priorityQueue.toArray(a)) {
        e.write(d);/*from   w w  w .j ava  2  s. c o  m*/
    }
}