List of usage examples for org.apache.hadoop.io IntWritable readFields
@Override public void readFields(DataInput in) throws IOException
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 ww .ja va 2s. c o m * @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.shaf.core.util.IOUtilsTest.java
License:Apache License
/** * Test writing of {@code integer} value. *///from ww w .j ava 2s .c o m @Test public void testWriteInt() { byte[] buf = null; int value = 123; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos);) { IOUtils.writeObject(value, out); buf = baos.toByteArray(); } catch (IOException exc) { fail(exc.getMessage()); } try (ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream in = new DataInputStream(bais);) { IntWritable probe = new IntWritable(); probe.readFields(in); assertEquals(value, probe.get()); } catch (IOException exc) { fail(exc.getMessage()); } }
From source file:org.shaf.core.util.IOUtilsTest.java
License:Apache License
/** * Test writing of {@code Array} value./*from w w w . j a va 2 s. c om*/ */ @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.shaf.core.util.IOUtilsTest.java
License:Apache License
/** * Test writing of {@code Enum} value./*from ww w.j a v a 2 s . c o m*/ */ @Test public void testWriteEnum() { byte[] buf = null; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos);) { IOUtils.writeObject(ActionType.MAP, out); buf = baos.toByteArray(); } catch (IOException exc) { fail(exc.getMessage()); } try (ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream in = new DataInputStream(bais);) { IntWritable probe = new IntWritable(); probe.readFields(in); assertEquals(ActionType.MAP, ActionType.values()[probe.get()]); } catch (IOException exc) { fail(exc.getMessage()); } }
From source file:tlfetl.card.TLFDWHValue.java
@Override public void readFields(DataInput di) throws IOException { FloatWritable writableAmount = new FloatWritable(); IntWritable writableCount = new IntWritable(); writableAmount.readFields(di);//from w w w . j ava 2 s. com writableCount.readFields(di); amount = writableAmount.get(); count = writableCount.get(); }
From source file:twitterpagerank.SortedPageRank.java
@Override public void readFields(DataInput di) throws IOException { IntWritable size = new IntWritable(); size.readFields(di); priorityQueue = new PriorityQueue<PageRankItem>(); for (int i = 0; i < size.get(); i++) { PageRankItem item = new PageRankItem(); item.readFields(di);/*from www .j a va 2s . c o m*/ priorityQueue.add(item); } }
From source file:utils.MyWritable.java
License:Apache License
public void readFields(DataInput in) throws IOException { values = new IntWritable[in.readInt()]; // construct values for (int i = 0; i < values.length; i++) { IntWritable value = new IntWritable(); value.readFields(in); // read a value values[i] = value; // store it in values }//from ww w .j a v a2s. c o m }