本文整理汇总了Java中java.io.DataInputStream类的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream类的具体用法?Java DataInputStream怎么用?Java DataInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataInputStream类属于java.io包,在下文中一共展示了DataInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeFirstLastKey
import java.io.DataInputStream; //导入依赖的package包/类
/**
* 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);
}
示例2: load
import java.io.DataInputStream; //导入依赖的package包/类
/**
* 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;
}
示例3: PacketResponder
import java.io.DataInputStream; //导入依赖的package包/类
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();
}
示例4: getUserList
import java.io.DataInputStream; //导入依赖的package包/类
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;
}
示例5: serializeTrieWithTwoValues
import java.io.DataInputStream; //导入依赖的package包/类
@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());
}
示例6: readAdditionalResults
import java.io.DataInputStream; //导入依赖的package包/类
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);
}
}
示例7: testKnownClassFiles
import java.io.DataInputStream; //导入依赖的package包/类
@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);
}
}
示例8: call
import java.io.DataInputStream; //导入依赖的package包/类
@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;
}
示例9: ExtractChunks
import java.io.DataInputStream; //导入依赖的package包/类
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;
}
示例10: Scanner
import java.io.DataInputStream; //导入依赖的package包/类
/**
* 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());
}
}
示例11: readRow
import java.io.DataInputStream; //导入依赖的package包/类
/** 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]);
}
}
}
示例12: DHTUDPPacketRequestPing
import java.io.DataInputStream; //导入依赖的package包/类
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);
}
示例13: filterIncomingMessage
import java.io.DataInputStream; //导入依赖的package包/类
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;
}
}
示例14: readVarInt
import java.io.DataInputStream; //导入依赖的package包/类
/**
* @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;
}
示例15: read
import java.io.DataInputStream; //导入依赖的package包/类
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);
}