List of usage examples for java.io DataInput readLong
long readLong() throws IOException;
From source file:org.apache.tez.mapreduce.hadoop.MRTaskStatus.java
@Override public void readFields(DataInput in) throws IOException { taskAttemptId = TezTaskAttemptID.read(in); state = WritableUtils.readEnum(in, State.class); progress = in.readFloat();/*from w w w .j a v a 2 s. c o m*/ diagnostics = WritableUtils.readString(in); userStatusInfo = WritableUtils.readString(in); phase = WritableUtils.readEnum(in, Phase.class); counters = new TezCounters(); counters.readFields(in); localOutputSize = in.readLong(); startTime = in.readLong(); finishTime = in.readLong(); sortFinishTime = in.readLong(); mapFinishTime = in.readLong(); shuffleFinishTime = in.readLong(); int numFailedDependencies = in.readInt(); for (int i = 0; i < numFailedDependencies; i++) { TezTaskAttemptID taskAttemptId = TezTaskAttemptID.read(in); failedTaskDependencies.add(taskAttemptId); } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *///from w w w . j av a 2 s. c om @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:org.cloudata.core.tablet.ColumnValue.java
public void readFields(DataInput in) throws IOException { //long startNano = System.nanoTime(); rowKey.readFields(in);/*w w w. j a v a 2 s . c o m*/ cellKey.readFields(in); int opCode = in.readInt(); if (opCode == Constants.DELETEED) { deleted = true; } else if (opCode == Constants.INSERTED) { deleted = false; } else { throw new IOException("Wrong record operation code(DELETEED or INSERTED): " + opCode); } timestamp = in.readLong(); numOfValues = in.readInt(); int valueLength = in.readInt(); //System.out.println(">>>>>" + valueLength); value = valueLength < 0 ? null : new byte[valueLength]; if (value != null) { in.readFully(value); } }
From source file:org.cloudata.core.tabletserver.CommitLog.java
public void readFields(DataInput in) throws IOException { operation = in.readInt();// w ww .ja v a 2s . co m rowKey.readFields(in); columnName = CWritableUtils.readString(in); columnKey.readFields(in); timestamp = in.readLong(); int length = in.readInt(); if (length > MAX_VALUE_SIZE) { LOG.error("number of bytes in commitlog exceeds CommitLog.MAX_VALUE_SIZE[" + MAX_VALUE_SIZE + "]"); throw new IOException("data size is too long.[" + length + "]"); } if (length >= 0) { value = new byte[length]; in.readFully(value); } }
From source file:org.commoncrawl.service.pagerank.slave.PageRankUtils.java
public static final int readURLFPAndCountFromStream(DataInput input, URLFPV2 fpOut) throws IOException { fpOut.setDomainHash(input.readLong()); fpOut.setRootDomainHash(input.readLong()); fpOut.setUrlHash(input.readLong());//from ww w . j av a 2 s .co m return WritableUtils.readVInt(input); }
From source file:org.commoncrawl.service.pagerank.slave.PageRankUtils.java
public static final void readURLFPFromStream(DataInput input, URLFPV2 fpOut) throws IOException { fpOut.setDomainHash(input.readLong()); fpOut.setRootDomainHash(input.readLong()); fpOut.setUrlHash(input.readLong());/*w w w.ja va 2 s .c o m*/ }
From source file:org.kiji.schema.mapreduce.KijiIncrement.java
/** {@inheritDoc} */ @Override// w w w . ja va2s . co m public void readFields(DataInput in) throws IOException { // EntityId. final byte[] bytes = new byte[in.readInt()]; in.readFully(bytes); mEntityId = new RawEntityId(bytes); // Family/Qualifier/Timestamp. mFamily = in.readUTF(); mQualifier = in.readUTF(); mAmount = in.readLong(); }
From source file:org.kiji.schema.mapreduce.KijiPut.java
/** {@inheritDoc} */ @Override//from www . j av a 2 s .c o m public void readFields(DataInput in) throws IOException { // EntityId. final byte[] bytes = new byte[in.readInt()]; in.readFully(bytes); mEntityId = new HBaseEntityId(bytes); // Family/Qualifier/Timestamp. mFamily = in.readUTF(); mQualifier = in.readUTF(); mTimestamp = in.readLong(); // Avro. final Schema schema = new Schema.Parser().parse(in.readUTF()); final KijiCellDecoderFactory decoderFactory = new SpecificCellDecoderFactory(null); final KijiCellDecoder<?> decoder = decoderFactory.create(schema, KijiCellFormat.NONE); final byte[] cellData = new byte[in.readInt()]; in.readFully(cellData); mCell = decoder.decode(cellData, null); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionFromData() throws Exception { final long expectedCreationTime = 1L; final long expectedLastAccessedTime = 2L; final int expectedMaxInactiveIntervalInSeconds = (int) TimeUnit.HOURS.toSeconds(6); final String expectedPrincipalName = "jblum"; DataInput mockDataInput = mock(DataInput.class); given(mockDataInput.readUTF()).willReturn("2").willReturn(expectedPrincipalName); given(mockDataInput.readLong()).willReturn(expectedCreationTime).willReturn(expectedLastAccessedTime); given(mockDataInput.readInt()).willReturn(expectedMaxInactiveIntervalInSeconds); @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession( "1") { @Override/* w ww . j ava2s . co m*/ @SuppressWarnings("unchecked") <T> T readObject(DataInput in) throws ClassNotFoundException, IOException { assertThat(in).isNotNull(); AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes sessionAttributes = new AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes(); sessionAttributes.setAttribute("attrOne", "testOne"); sessionAttributes.setAttribute("attrTwo", "testTwo"); return (T) sessionAttributes; } }; session.fromData(mockDataInput); Set<String> expectedAttributeNames = asSet("attrOne", "attrTwo", FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME); assertThat(session.getId()).isEqualTo("2"); assertThat(session.getCreationTime()).isEqualTo(expectedCreationTime); assertThat(session.getLastAccessedTime()).isEqualTo(expectedLastAccessedTime); assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(expectedMaxInactiveIntervalInSeconds); assertThat(session.getPrincipalName()).isEqualTo(expectedPrincipalName); assertThat(session.getAttributeNames().size()).isEqualTo(3); assertThat(session.getAttributeNames().containsAll(expectedAttributeNames)).isTrue(); assertThat(String.valueOf(session.getAttribute("attrOne"))).isEqualTo("testOne"); assertThat(String.valueOf(session.getAttribute("attrTwo"))).isEqualTo("testTwo"); assertThat(String.valueOf(session.getAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME))) .isEqualTo(expectedPrincipalName); verify(mockDataInput, times(2)).readUTF(); verify(mockDataInput, times(2)).readLong(); verify(mockDataInput, times(2)).readInt(); }
From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepositoryTest.java
@Test public void sessionFromDelta() throws Exception { final DataInput mockDataInput = mock(DataInput.class); given(mockDataInput.readLong()).willReturn(1L); given(mockDataInput.readInt()).willReturn(600).willReturn(0); @SuppressWarnings("serial") AbstractGemFireOperationsSessionRepository.GemFireSession session = new AbstractGemFireOperationsSessionRepository.GemFireSession() { @Override/*from w ww . j a v a 2 s.c o m*/ @SuppressWarnings("unchecked") <T> T readObject(DataInput in) throws ClassNotFoundException, IOException { assertThat(in).isSameAs(mockDataInput); return (T) "test"; } }; session.fromDelta(mockDataInput); assertThat(session.hasDelta()).isFalse(); assertThat(session.getLastAccessedTime()).isEqualTo(1L); assertThat(session.getMaxInactiveIntervalInSeconds()).isEqualTo(600); assertThat(session.getAttributeNames().isEmpty()).isTrue(); verify(mockDataInput, times(1)).readLong(); verify(mockDataInput, times(2)).readInt(); verify(mockDataInput, never()).readUTF(); }