當前位置: 首頁>>代碼示例>>Java>>正文


Java DataInputStream類代碼示例

本文整理匯總了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);
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:21,代碼來源:IndexSummary.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:BinaryAttribute.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:BlockReceiver.java

示例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;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:27,代碼來源:WeiXinUserUtils.java

示例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());
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:20,代碼來源:TrieImplTrieSerializationTests.java

示例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);
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:21,代碼來源:Result.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:Basic.java

示例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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:MTableOverflowToTierTest.java

示例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;
}
 
開發者ID:timerickson,項目名稱:lastpass-java,代碼行數:20,代碼來源:ParserHelper.java

示例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());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:TFile.java

示例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]);
		}
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:20,代碼來源:ExampleSetToStream.java

示例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);
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:19,代碼來源:DHTUDPPacketRequestPing.java

示例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;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:27,代碼來源:JGroupsMessenger.java

示例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;
}
 
開發者ID:SamaGames,項目名稱:Hydroangeas,代碼行數:22,代碼來源:MinecraftPingUtil.java

示例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);
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:25,代碼來源:Cave.java


注:本文中的java.io.DataInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。