Java Code Examples for java.io.DataInputStream

The following are top voted examples for showing how to use java.io.DataInputStream. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sstable-adaptor   File: IndexSummary.java   View source code 6 votes vote down vote up
/**
 * Deserializes the first and last key stored in the summary
 *
 * Only for use by offline tools like SSTableMetadataViewer, otherwise SSTable.first/last should be used.
 */
public Pair<DecoratedKey, DecoratedKey> deserializeFirstLastKey(DataInputStream in, IPartitioner partitioner, boolean haveSamplingLevel) throws IOException
{
    in.skipBytes(4); // minIndexInterval
    int offsetCount = in.readInt();
    long offheapSize = in.readLong();
    if (haveSamplingLevel)
        in.skipBytes(8); // samplingLevel, fullSamplingSummarySize

    in.skip(offsetCount * 4);
    in.skip(offheapSize - offsetCount * 4);

    DecoratedKey first = partitioner.decorateKey(ByteBufferUtil.readWithLength(in));
    DecoratedKey last = partitioner.decorateKey(ByteBufferUtil.readWithLength(in));
    return Pair.create(first, last);
}
 
Example 2
Project: OpenJSharp   File: BinaryAttribute.java   View source code 6 votes vote down vote up
/**
 * Load a list of attributes
 */
public static BinaryAttribute load(DataInputStream in, BinaryConstantPool cpool, int mask) throws IOException {
    BinaryAttribute atts = null;
    int natt = in.readUnsignedShort();  // JVM 4.6 method_info.attrutes_count

    for (int i = 0 ; i < natt ; i++) {
        // id from JVM 4.7 attribute_info.attribute_name_index
        Identifier id = cpool.getIdentifier(in.readUnsignedShort());
        // id from JVM 4.7 attribute_info.attribute_length
        int len = in.readInt();

        if (id.equals(idCode) && ((mask & ATT_CODE) == 0)) {
            in.skipBytes(len);
        } else {
            byte data[] = new byte[len];
            in.readFully(data);
            atts = new BinaryAttribute(id, data, atts);
        }
    }
    return atts;
}
 
Example 3
Project: hadoop   File: BlockReceiver.java   View source code 6 votes vote down vote up
PacketResponder(final DataOutputStream upstreamOut,
    final DataInputStream downstreamIn, final DatanodeInfo[] downstreams) {
  this.downstreamIn = downstreamIn;
  this.upstreamOut = upstreamOut;

  this.type = downstreams == null? PacketResponderType.NON_PIPELINE
      : downstreams.length == 0? PacketResponderType.LAST_IN_PIPELINE
          : PacketResponderType.HAS_DOWNSTREAM_IN_PIPELINE;

  final StringBuilder b = new StringBuilder(getClass().getSimpleName())
      .append(": ").append(block).append(", type=").append(type);
  if (type != PacketResponderType.HAS_DOWNSTREAM_IN_PIPELINE) {
    b.append(", downstreams=").append(downstreams.length)
        .append(":").append(Arrays.asList(downstreams));
  }
  this.myString = b.toString();
}
 
Example 4
Project: iBase4J-Common   File: WeiXinUserUtils.java   View source code 6 votes vote down vote up
public static String getUserList(String next_openid) {
	String token = WeiXinUtils.getToken();
	if (token != null) {
		String urlString = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + token;
		if (next_openid != null) {
			urlString = urlString + "&next_openid=" + next_openid;
		}
		try {
			URL url = new URL(urlString);
			HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
			httpsURLConnection.setDoInput(true);
			DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
			StringBuffer stringBuffer = new StringBuffer();
			int inputByte = dataInputStream.read();
			while (inputByte != -1) {
				stringBuffer.append((char) inputByte);
				inputByte = dataInputStream.read();
			}
			String kfString = stringBuffer.toString();
			return kfString;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	return null;
}
 
Example 5
Project: rskj   File: TrieImplTrieSerializationTests.java   View source code 6 votes vote down vote up
@Test
public void serializeTrieWithTwoValues() throws IOException {
    Trie trie = new TrieImpl()
            .put("foo".getBytes(), "bar".getBytes())
            .put("bar".getBytes(), "foo".getBytes());

    byte[] bytes = ((TrieImpl)trie).serializeTrie();

    Assert.assertNotNull(bytes);

    byte[] message = trie.toMessage();

    ByteArrayInputStream bstream = new ByteArrayInputStream(bytes);
    DataInputStream ostream = new DataInputStream(bstream);

    Assert.assertEquals(0, ostream.readShort());
    Assert.assertEquals(2, ostream.readShort());
    Assert.assertEquals(message.length, ostream.readInt());
}
 
Example 6
Project: OpenDiabetes   File: Result.java   View source code 6 votes vote down vote up
public void readAdditionalResults(SessionInterface session,
                                  DataInputStream inputStream,
                                  RowInputBinary in) throws IOException {

    Result currentResult = this;

    setSession(session);

    while (true) {
        int addedResultMode = inputStream.readByte();

        if (addedResultMode == ResultConstants.NONE) {
            return;
        }

        currentResult = newResult(null, inputStream, in, addedResultMode);

        addChainedResult(currentResult);
    }
}
 
Example 7
Project: openjdk-jdk10   File: Basic.java   View source code 6 votes vote down vote up
@Test(dataProvider = "knownClassFiles")
public void testKnownClassFiles(String path, boolean theDefault) throws Exception {
    if (isExplodedBuild && !theDefault) {
        System.out.println("Skip testKnownClassFiles with non-default FileSystem");
        return;
    }

    FileSystem fs = selectFileSystem(theDefault);
    Path classFile = fs.getPath(path);

    assertTrue(Files.isRegularFile(classFile));
    assertTrue(Files.size(classFile) > 0L);

    // check magic number
    try (InputStream in = Files.newInputStream(classFile)) {
        int magic = new DataInputStream(in).readInt();
        assertEquals(magic, 0xCAFEBABE);
    }
}
 
Example 8
Project: monarch   File: MTableOverflowToTierTest.java   View source code 6 votes vote down vote up
@Override
public Object call() throws Exception {
  MCacheFactory.getAnyInstance().getResourceManager()
      .setEvictionHeapPercentage(EVICT_HEAP_PCT);
  final PartitionedRegion pr =
      (PartitionedRegion) MCacheFactory.getAnyInstance().getRegion(TABLE_NAME);
  if (debug)
    System.out.println("MTableOverflowToTierTest.call YYYYYYYYYYYYYYYY");
  assertNotNull(pr);
  int count = 0;
  /** get the total count of number of entries from overflow-tier **/
  for (final BucketRegion br : pr.getDataStore().getAllLocalBucketRegions()) {
    FileInputStream fis = new FileInputStream(TierHelper.getTierFileNameKeys(br));
    DataInputStream dis = new DataInputStream(new BufferedInputStream(fis, 32768));
    while (dis.available() > 0) {
      DataSerializer.readObject(dis);
      count++;
    }
    dis.close();
  }
  return count;
}
 
Example 9
Project: lastpass-java   File: ParserHelper.java   View source code 6 votes vote down vote up
public List<Chunk> ExtractChunks(DataInputStream reader) {
    List<Chunk> chunks = new ArrayList<>();
    try
    {
        boolean stopped = false;
        while (!stopped) {
            chunks.add(ReadChunk(reader));
        }
    }
    catch (Exception e)
    {
        // In case the stream is truncated we just ignore the incomplete chunk.
        if (!(e.getCause() instanceof IOException)) {
            throw e;
        }
    }

    return chunks;
}
 
Example 10
Project: hadoop   File: TFile.java   View source code 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param reader
 *          The TFile reader object.
 * @param begin
 *          Begin location of the scan.
 * @param end
 *          End location of the scan.
 * @throws IOException
 */
Scanner(Reader reader, Location begin, Location end) throws IOException {
  this.reader = reader;
  // ensure the TFile index is loaded throughout the life of scanner.
  reader.checkTFileDataIndex();
  beginLocation = begin;
  endLocation = end;

  valTransferBuffer = new BytesWritable();
  // TODO: remember the longest key in a TFile, and use it to replace
  // MAX_KEY_SIZE.
  keyBuffer = new byte[MAX_KEY_SIZE];
  keyDataInputStream = new DataInputBuffer();
  valueBufferInputStream = new ChunkDecoder();
  valueDataInputStream = new DataInputStream(valueBufferInputStream);

  if (beginLocation.compareTo(endLocation) >= 0) {
    currentLocation = new Location(endLocation);
  } else {
    currentLocation = new Location(0, 0);
    initBlock(beginLocation.getBlockIndex());
    inBlockAdvance(beginLocation.getRecordIndex());
  }
}
 
Example 11
Project: rapidminer   File: ExampleSetToStream.java   View source code 6 votes vote down vote up
/** Reads a single row from the stream. */
public void readRow(final DataInputStream in, final double[] data, final ColumnType[] columnTypes, final boolean sparse,
		final double[] sparseDefaults) throws IOException {
	if (sparse) {
		System.arraycopy(sparseDefaults, 0, data, 0, sparseDefaults.length);
		while (true) {
			int index = in.readInt();
			if (index == -1) {
				break;
			} else {
				data[index] = readDatum(in, columnTypes[index]);
			}
		}
	} else {
		for (int attIndex = 0; attIndex < columnTypes.length; attIndex++) {
			data[attIndex] = readDatum(in, columnTypes[attIndex]);
		}
	}
}
 
Example 12
Project: BiglyBT   File: DHTUDPPacketRequestPing.java   View source code 6 votes vote down vote up
protected
DHTUDPPacketRequestPing(
	DHTUDPPacketNetworkHandler		network_handler,
	DataInputStream					is,
	long							con_id,
	int								trans_id )

	throws IOException
{
	super( network_handler, is,  DHTUDPPacketHelper.ACT_REQUEST_PING, con_id, trans_id );

	if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ALT_CONTACTS ){

		DHTUDPUtils.deserialiseAltContactRequest( this, is );
	}

	super.postDeserialise(is);
}
 
Example 13
Project: monarch   File: JGroupsMessenger.java   View source code 6 votes vote down vote up
void filterIncomingMessage(DistributionMessage m) {
  switch (m.getDSFID()) {
    case JOIN_RESPONSE:
      JoinResponseMessage jrsp = (JoinResponseMessage) m;

      if (jrsp.getRejectionMessage() == null
          && services.getConfig().getTransport().isMcastEnabled()) {
        byte[] serializedDigest = jrsp.getMessengerData();
        ByteArrayInputStream bis = new ByteArrayInputStream(serializedDigest);
        DataInputStream dis = new DataInputStream(bis);
        try {
          Digest digest = new Digest();
          digest.readFrom(dis);
          logger.trace("installing JGroups message digest {}", digest);
          this.myChannel.getProtocolStack().getTopProtocol()
              .down(new Event(Event.MERGE_DIGEST, digest));
          jrsp.setMessengerData(null);
        } catch (Exception e) {
          logger.fatal("Unable to read JGroups messaging digest", e);
        }
      }
      break;
    default:
      break;
  }
}
 
Example 14
Project: Hydroangeas   File: MinecraftPingUtil.java   View source code 6 votes vote down vote up
/**
 * @author thinkofdeath
 * See: https://gist.github.com/thinkofdeath/e975ddee04e9c87faf22
 */
public static int readVarInt(DataInputStream in) throws IOException {
    int i = 0;
    int j = 0;
    while (true) {
        int k = in.readByte();

        i |= (k & 0x7F) << j++ * 7;

        if (j > 5)
            throw new RuntimeException("VarInt too big");

        if ((k & 0x80) != 128)
            break;
    }

    return i;
}
 
Example 15
Project: Cubes   File: Cave.java   View source code 6 votes vote down vote up
public static Cave read(DataInputStream inputStream) throws IOException {
  int caveStartX = inputStream.readInt();
  int caveStartY = inputStream.readInt();
  int caveStartZ = inputStream.readInt();
  int mapSize = inputStream.readInt();

  HashMap<AreaReference, int[]> blocks = new HashMap<AreaReference, int[]>();

  for (int i = 0; i < mapSize; i++) {
    int areaX = inputStream.readInt();
    int areaZ = inputStream.readInt();
    int valueLength = inputStream.readInt();

    AreaReference areaReference = new AreaReference().setFromAreaCoordinates(areaX, areaZ);
    int[] value = new int[valueLength];

    for (int j = 0; j < valueLength; j++) {
      value[j] = inputStream.readInt();
    }

    blocks.put(areaReference, value);
  }
  return new Cave(caveStartX, caveStartY, caveStartZ, blocks);
}
 
Example 16
Project: googles-monorepo-demo   File: LittleEndianDataOutputStreamTest.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation") // testing a deprecated method
public void testWriteBytes() throws IOException {

  /* Write out various test values in LITTLE ENDIAN FORMAT */
  out.writeBytes("r\u00C9sum\u00C9");

  byte[] data = baos.toByteArray();

  /* Setup input streams */
  DataInput in = new DataInputStream(new ByteArrayInputStream(data));

  /* Read in various values NORMALLY */
  byte[] b = new byte[6];
  in.readFully(b);
  assertEquals("r\u00C9sum\u00C9".getBytes(Charsets.ISO_8859_1), b);
}
 
Example 17
Project: hadoop   File: EditLogFileInputStream.java   View source code 6 votes vote down vote up
/**
 * Read the header of fsedit log
 * @param in fsedit stream
 * @return the edit log version number
 * @throws IOException if error occurs
 */
@VisibleForTesting
static int readLogVersion(DataInputStream in, boolean verifyLayoutVersion)
    throws IOException, LogHeaderCorruptException {
  int logVersion;
  try {
    logVersion = in.readInt();
  } catch (EOFException eofe) {
    throw new LogHeaderCorruptException(
        "Reached EOF when reading log header");
  }
  if (verifyLayoutVersion &&
      (logVersion < HdfsConstants.NAMENODE_LAYOUT_VERSION || // future version
       logVersion > Storage.LAST_UPGRADABLE_LAYOUT_VERSION)) { // unsupported
    throw new LogHeaderCorruptException(
        "Unexpected version of the file system log file: "
        + logVersion + ". Current version = "
        + HdfsConstants.NAMENODE_LAYOUT_VERSION + ".");
  }
  return logVersion;
}
 
Example 18
Project: incubator-netbeans   File: LayerCacheManager.java   View source code 6 votes vote down vote up
@Override
public FileSystem load(FileSystem previous, ByteBuffer bb) throws IOException {
    byte[] arr = new byte[bb.limit()];
    bb.get(arr);
    DataInputStream is = new DataInputStream(new ByteArrayInputStream(arr));
    List<URL> urls = new ArrayList<URL>();
    while (is.available() > 0) {
        String u = is.readUTF();
        urls.add(new URL(u));
    }
    try {
        XMLFileSystem fs = (XMLFileSystem)previous;
        fs.setXmlUrls(urls.toArray(new URL[urls.size()]));
        return fs;
    } catch (PropertyVetoException pve) {
        throw (IOException) new IOException(pve.toString()).initCause(pve);
    }
}
 
Example 19
Project: monarch   File: DiskInitFile.java   View source code 6 votes vote down vote up
private PersistentMemberID bytesToPMID(byte[] bytes) {
  try {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(bais);
    PersistentMemberID result = new PersistentMemberID();
    InternalDataSerializer.invokeFromData(result, dis);
    return result;
  } catch (IOException io) {
    throw new DiskAccessException(
        LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0
            .toLocalizedString(this.ifFile.getPath()),
        io, this.parent);
  } catch (ClassNotFoundException cnf) {
    throw new DiskAccessException(
        LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0
            .toLocalizedString(this.ifFile.getPath()),
        cnf, this.parent);
  }
}
 
Example 20
Project: incubator-netbeans   File: LocalVariableTableEntry.java   View source code 6 votes vote down vote up
private void loadLocalVariableEntry(DataInputStream in, ConstantPool pool) 
  throws IOException {
    startPC = in.readUnsignedShort();
    length = in.readUnsignedShort();
    Object o = pool.get(in.readUnsignedShort());
    if (!(o instanceof CPUTF8Info))
      throw new InvalidClassFormatException();
    CPUTF8Info entry = (CPUTF8Info)o;
    name = entry.getName();
    o = pool.get(in.readUnsignedShort());
    if (!(o instanceof CPUTF8Info))
      throw new InvalidClassFormatException();
    entry = (CPUTF8Info)o;
    description = entry.getName();
    index = in.readUnsignedShort();
}
 
Example 21
Project: openjdk-jdk10   File: DTD.java   View source code 6 votes vote down vote up
private AttributeList readAttributeList(DataInputStream in, String[] names)
                throws IOException  {
        AttributeList result = null;
        for (int num = in.readByte(); num > 0; --num) {
            short nameId = in.readShort();
            int type = in.readByte();
            int modifier = in.readByte();
            short valueId = in.readShort();
            String value = (valueId == -1) ? null : names[valueId];
            Vector<String> values = null;
            short numValues = in.readShort();
            if (numValues > 0) {
                values = new Vector<String>(numValues);
                for (int i = 0; i < numValues; i++) {
                    values.addElement(names[in.readShort()]);
                }
            }
result = new AttributeList(names[nameId], type, modifier, value,
                                       values, result);
            // We reverse the order of the linked list by doing this, but
            // that order isn't important.
        }
        return result;
    }
 
Example 22
Project: incubator-netbeans   File: Method.java   View source code 6 votes vote down vote up
/**
    * Returns the default annotation value for the element
    * defined by this method.  Null is returned if no default 
    * is specified for this element, or if the class that contains 
    * this method does not define an annotation type.
    */
   public ElementValue getAnnotationDefault() {
if (annotationDefault == notloadedAnnotationDefault) {
           annotationDefault = null;
    DataInputStream in = 
	attributes.getStream("AnnotationDefault"); // NOI18N
    if (in != null) {
	try {
	    annotationDefault = 
		ElementValue.load(in, classFile.constantPool, false);
	    in.close();
	} catch (IOException e) {
	    throw new InvalidClassFileAttributeException("invalid AnnotationDefault attribute", e);
	}
    }
}
       return annotationDefault;
   }
 
Example 23
Project: geomapapp   File: HeatFlux.java   View source code 5 votes vote down vote up
static void load() throws IOException {
	q = new float[11][130][102];
	URL url = URLFactory.url(haxby.map.MapApp.TEMP_BASE_URL + "arctic/ice/heatflux");
	DataInputStream in = new DataInputStream(url.openStream());
	for( int year=0 ; year<11 ; year++ ) {
			for(int y=0 ; y<102 ; y++) {
		for(int x=0 ; x<130 ; x++) {
				q[year][x][y] = in.readFloat();
			}
		}
	}
	in.close();
	loaded = true;
}
 
Example 24
Project: iBase4J   File: WeiXinKFUtils.java   View source code 5 votes vote down vote up
/**
 * 添加客服帐号
 *
 * @param keFu
 * @return
 */
public static boolean insertKfAccount(KeFu keFu) {
    boolean isOk = false;
    String token = WeiXinUtils.getToken();
    if (token != null) {
        String urlString = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + token;
        try {
            URL url = new URL(urlString);
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
            String kfAccountString = JSONObject.toJSONString(keFu);
            httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
            httpsURLConnection.setRequestProperty("Content-Type", "application/json");
            httpsURLConnection.setDoOutput(true);
            httpsURLConnection.setDoInput(true);
            DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
            dataOutputStream.write(kfAccountString.getBytes());
            dataOutputStream.flush();
            dataOutputStream.close();
            DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
            StringBuffer stringBuffer = new StringBuffer();
            int inputByte = dataInputStream.read();
            while (inputByte != -1) {
                stringBuffer.append((char) inputByte);
                inputByte = dataInputStream.read();
            }
            String kfString = stringBuffer.toString();
            JSONObject jsonObject = JSON.parseObject(kfString);
            if (jsonObject.containsKey("errcode")) {
                int errcode = jsonObject.getIntValue("errcode");
                if (errcode == 0) {
                    isOk = true;
                } else {
                    //TODO 添加客服账号失败
                    isOk = false;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return isOk;
}
 
Example 25
Project: openjdk-jdk10   File: ClassfileBytecode.java   View source code 5 votes vote down vote up
@Override
public LocalVariableTable getLocalVariableTable() {
    if (localVariableTableBytes == null) {
        return null;
    }

    final int localVariableTableLength = localVariableTableBytes.length / LOCAL_VARIABLE_TABLE_SIZE_IN_BYTES;
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(localVariableTableBytes));
    Local[] locals = new Local[localVariableTableLength];

    for (int i = 0; i < localVariableTableLength; i++) {
        try {
            final int startBci = stream.readUnsignedShort();
            final int endBci = startBci + stream.readUnsignedShort();
            final int nameCpIndex = stream.readUnsignedShort();
            final int typeCpIndex = stream.readUnsignedShort();
            final int slot = stream.readUnsignedShort();

            String localName = constantPool.lookupUtf8(nameCpIndex);
            String localType = constantPool.lookupUtf8(typeCpIndex);

            ClassfileBytecodeProvider context = constantPool.context;
            Class<?> c = context.resolveToClass(localType);
            locals[i] = new Local(localName, context.metaAccess.lookupJavaType(c), startBci, endBci, slot);
        } catch (IOException e) {
            throw new GraalError(e);
        }
    }

    return new LocalVariableTable(locals);
}
 
Example 26
Project: CoreX   File: Chunk.java   View source code 5 votes vote down vote up
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN);
        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }

        return new Chunk(provider, chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 27
Project: hadoop   File: ZKDelegationTokenSecretManager.java   View source code 5 votes vote down vote up
private void processKeyAddOrUpdate(byte[] data) throws IOException {
  ByteArrayInputStream bin = new ByteArrayInputStream(data);
  DataInputStream din = new DataInputStream(bin);
  DelegationKey key = new DelegationKey();
  key.readFields(din);
  synchronized (this) {
    allKeys.put(key.getKeyId(), key);
  }
}
 
Example 28
Project: Jupiter   File: Chunk.java   View source code 5 votes vote down vote up
public static Chunk fromFastBinary(byte[] data, LevelProvider provider) {
    try {
        CompoundTag chunk = NBTIO.read(new DataInputStream(new ByteArrayInputStream(data)), ByteOrder.BIG_ENDIAN);
        if (!chunk.contains("Level") || !(chunk.get("Level") instanceof CompoundTag)) {
            return null;
        }

        return new Chunk(provider, chunk.getCompound("Level"));
    } catch (Exception e) {
        return null;
    }
}
 
Example 29
Project: monarch   File: AColumnStatisticsTest.java   View source code 5 votes vote down vote up
/**
 * Simple test that asserts the statistics are correctly stored for the types even with serialize
 * and de-serialize. Also assert that min changes accordingly when null values are passed as for
 * fixed length columns use default values.
 *
 * @throws IOException if not able to read/write
 * @throws ClassNotFoundException the class does not exist
 */
@Test
public void testStatisticsBasic() throws IOException, ClassNotFoundException {
  final Object[] values = new Object[] {1, 11.11, "abc_EFG", Date.valueOf("2017-10-10"),
      new Timestamp(123456789L), new Object[] {55L, 56L, 57L}};
  final String[] expected =
      new String[] {"1", "11.11", "abc_EFG", "2017-10-10", "1970-01-02 15:47:36.789", null};
  final String[] expectedMin =
      new String[] {"0", "0.0", "abc_EFG", "1970-01-01", "1970-01-01 05:30:00.0", null};

  final AColumnStatistics acs = new AColumnStatistics(TD);
  row.reset(null, enc.serializeValue(TD, record.reset(values)), enc, null);
  acs.updateRowStatistics(TD.getAllColumnDescriptors(), row);

  assertColumnStatistics(expected, expected, acs);

  final HeapDataOutputStream out = new HeapDataOutputStream(1024, null);
  DataSerializer.writeObject(acs, out);
  final byte[] dataBytes = out.toByteArray();

  AColumnStatistics ncs =
      DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(dataBytes)));

  assertColumnStatistics(expected, expected, ncs);

  row.reset(null, enc.serializeValue(TD, record.reset(new Object[TD.getNumOfColumns()])), enc,
      null);
  acs.updateRowStatistics(TD.getAllColumnDescriptors(), row);
  assertColumnStatistics(expectedMin, expected, acs);
}
 
Example 30
Project: Reer   File: BTreePersistentIndexedCache.java   View source code 5 votes vote down vote up
public void read(DataInputStream instr) throws IOException {
    int count = instr.readInt();
    entries.clear();
    for (int i = 0; i < count; i++) {
        IndexEntry entry = new IndexEntry();
        entry.hashCode = instr.readLong();
        entry.dataBlock = new BlockPointer(instr.readLong());
        entry.childIndexBlock = new BlockPointer(instr.readLong());
        entries.add(entry);
    }
    tailPos = new BlockPointer(instr.readLong());
}
 
Example 31
Project: geomapapp   File: USGS_DEM.java   View source code 5 votes vote down vote up
public void readHeader() throws IOException {
	DataInputStream in = zipped
		? new DataInputStream(
			new GZIPInputStream( url.openStream() ))
		: new DataInputStream( url.openStream() );
	readHeader(in);
	in.close();
}
 
Example 32
Project: fuck_zookeeper   File: QuorumCnxManager.java   View source code 5 votes vote down vote up
RecvWorker(Socket sock, Long sid, SendWorker sw) {
    super("RecvWorker:" + sid);
    this.sid = sid;
    this.sock = sock;
    this.sw = sw;
    try {
        din = new DataInputStream(sock.getInputStream());
        // OK to wait until socket disconnects while reading.
        sock.setSoTimeout(0);
    } catch (IOException e) {
        LOG.error("Error while accessing socket for " + sid, e);
        closeSocket(sock);
        running = false;
    }
}
 
Example 33
Project: hadoop-oss   File: ZKDelegationTokenSecretManager.java   View source code 5 votes vote down vote up
private DelegationTokenInformation getTokenInfoFromZK(TokenIdent ident,
    boolean quiet) throws IOException {
  String nodePath =
      getNodePath(ZK_DTSM_TOKENS_ROOT,
          DELEGATION_TOKEN_PREFIX + ident.getSequenceNumber());
  try {
    byte[] data = zkClient.getData().forPath(nodePath);
    if ((data == null) || (data.length == 0)) {
      return null;
    }
    ByteArrayInputStream bin = new ByteArrayInputStream(data);
    DataInputStream din = new DataInputStream(bin);
    createIdentifier().readFields(din);
    long renewDate = din.readLong();
    int pwdLen = din.readInt();
    byte[] password = new byte[pwdLen];
    int numRead = din.read(password, 0, pwdLen);
    if (numRead > -1) {
      DelegationTokenInformation tokenInfo =
          new DelegationTokenInformation(renewDate, password);
      return tokenInfo;
    }
  } catch (KeeperException.NoNodeException e) {
    if (!quiet) {
      LOG.error("No node in path [" + nodePath + "]");
    }
  } catch (Exception ex) {
    throw new IOException(ex);
  }
  return null;
}
 
Example 34
Project: angel   File: ServerMatrix.java   View source code 5 votes vote down vote up
/**
 * Read partitions of matrix from input
 *
 * @param input the input
 * @throws IOException
 */
public void readSnapshot(DataInputStream input) throws IOException {
  int partitionNum = input.readInt();
  LOG.info("partitionNum=" + partitionNum);
  if (LOG.isDebugEnabled()) {
    LOG.debug("readFrom input, matrixId: " + matrixId + ", partitionNum: " + partitionNum);
  }
  for (int i = 0; i < partitionNum; i++) {
    int partitionId = input.readInt();
    LOG.debug("parse partitionId: " + partitionId);
    partitionMaps.get(partitionId).load(input);
  }
}
 
Example 35
Project: LT-ABSA   File: GloVeSpace.java   View source code 5 votes vote down vote up
/**
 * Read a Vector - Array from binary file
 * @param ds input data stream
 * @param vectorSize length of each word vector
 * @return an array of float containing the word vector representation
 */
private static float[] readFloatVector(DataInputStream ds, int vectorSize) throws IOException {
    float[] vector = new float[vectorSize];
    for (int j = 0; j < vectorSize; j++) {
        long l = ds.readLong();
        float d = (float)(Long.reverseBytes(l));
        vector[j] = d;
    }
    return vector;
}
 
Example 36
Project: phonk   File: PBluetoothServer.java   View source code 5 votes vote down vote up
ConnectionThread(ConnectedDevice connectedDevice) {
    mmConectedDevice = connectedDevice;
    mmBtSocketClient = connectedDevice.bluetoothSocket;
    try {
        outputStream = mmBtSocketClient.getOutputStream();
        inputStream = mmBtSocketClient.getInputStream();
        dataInputStream = new DataInputStream(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    MLog.d(TAG, "bbt start connection thread " + inputStream + " " + dataInputStream + " " + outputStream);
}
 
Example 37
Project: Brevent   File: BreventProtocol.java   View source code 5 votes vote down vote up
@WorkerThread
public static boolean checkPortSync() throws IOException {
    try (
            Socket socket = new Socket(InetAddress.getLoopbackAddress(), BreventProtocol.PORT);
            DataOutputStream os = new DataOutputStream(socket.getOutputStream());
            DataInputStream is = new DataInputStream(socket.getInputStream())
    ) {
        os.writeShort(0);
        os.flush();
        return BreventProtocol.readFrom(is) == BreventOK.INSTANCE;
    }
}
 
Example 38
Project: ditb   File: IndexTableRelation.java   View source code 5 votes vote down vote up
public static IndexTableRelation getIndexTableRelation(HTableDescriptor desc) throws IOException {
  byte[] bytes;
  if (desc != null && (bytes = desc.getValue(INDEX_ATTRIBUTE_NAME_BYTES)) != null) {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(inputStream);
    IndexTableRelation rl = new IndexTableRelation(desc.getTableName(), IndexType.NoIndex);
    rl.readFields(dis);
    return rl;
  }
  LOG.info("index table relation = null, because " + (desc == null ?
      "desc is null" :
      ("attribute is null for table " + desc.getTableName())));
  return null;
}
 
Example 39
Project: KraftigAudio   File: Oscilloscope.java   View source code 5 votes vote down vote up
@Override
public void load(DataInputStream in) throws IOException
{
    super.load(in);
    modeRadio.load(in);
    brightnessKnob.load(in);
}
 
Example 40
Project: JRF   File: MsgAck.java   View source code 5 votes vote down vote up
@Override
protected void decode(byte[] buf) throws IOException {
	try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf))) {
		fileID = dis.readShort();
		code = dis.readLong();
		int n = dis.readInt();
		if (n < 0)
			msg = null;
		else if (n == 0)
			msg = "";
		else
			msg = Utils.readString(dis);
	}
}