博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java socket datainputstream_Java DataInputStream.available方法代碼示例
阅读量:5300 次
发布时间:2019-06-14

本文共 17567 字,大约阅读时间需要 58 分钟。

本文整理匯總了Java中java.io.DataInputStream.available方法的典型用法代碼示例。如果您正苦於以下問題:Java DataInputStream.available方法的具體用法?Java DataInputStream.available怎麽用?Java DataInputStream.available使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.DataInputStream的用法示例。

在下文中一共展示了DataInputStream.available方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: load

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

@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 urls = new ArrayList();

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);

}

}

開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,

示例2: stream

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

/**

* This method returns a ByteArrayInputStream that contains an internal

* buffer of bytes that may be read from the stream

*/

@SuppressWarnings("resource")

private InputStream stream(String fileName) throws IOException {

// ---- Create a FileInputStream ------------------------------

FileInputStream fileInputStream = new FileInputStream(fileName);

// ---- Create a DataInputStream ------------------------------

DataInputStream dataInputStream = new DataInputStream(fileInputStream);

// ---- Put the dataInputStream in Byte[] ---------------------

byte[] bytes = new byte[dataInputStream.available()];

// ---- Read the bytes ----------------------------------------

dataInputStream.readFully(bytes);

// ---- Create a ByteArrayInputStream -------------------------

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

return byteArrayInputStream;

}

開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:20,

示例3: PRUDPPacketReplyScrape2

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

protected

PRUDPPacketReplyScrape2(

DataInputStreamis,

inttrans_id )

throws IOException

{

super( PRUDPPacketTracker.ACT_REPLY_SCRAPE, trans_id );

// interval = is.readInt();

complete= new int[is.available()/BYTES_PER_ENTRY];

incomplete= new int[complete.length];

downloaded= new int[complete.length];

for (int i=0;i

complete[i] = is.readInt();

downloaded[i] = is.readInt();

incomplete[i] = is.readInt();

}

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:23,

示例4: getClassBody

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

private byte[] getClassBody(Object task) {

Class> c = task.getClass();

byte[] classBody = class2bytes.get(c);

if (classBody == null) {

String className = c.getName();

String classAsPath = className.replace('.', '/') + ".class";

InputStream classStream = c.getClassLoader().getResourceAsStream(classAsPath);

DataInputStream s = new DataInputStream(classStream);

try {

classBody = new byte[s.available()];

s.readFully(classBody);

} catch (IOException e) {

throw new IllegalArgumentException(e);

}

class2bytes.put(c, classBody);

}

return classBody;

}

開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,

示例5: internalDecodeKeyValues

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

@Override

protected ByteBuffer internalDecodeKeyValues(DataInputStream source, int allocateHeaderLength,

int skipLastBytes, HFileBlockDefaultDecodingContext decodingCtx) throws IOException {

int decompressedSize = source.readInt();

ByteBuffer buffer = ByteBuffer.allocate(decompressedSize +

allocateHeaderLength);

buffer.position(allocateHeaderLength);

DiffCompressionState state = new DiffCompressionState();

while (source.available() > skipLastBytes) {

uncompressSingleKeyValue(source, buffer, state);

afterDecodingKeyValue(source, buffer, decodingCtx);

}

if (source.available() != skipLastBytes) {

throw new IllegalStateException("Read too much bytes.");

}

return buffer;

}

開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,

示例6: tryConnect

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

private void tryConnect() throws IOException {

Socket socket = new Socket(Config.SERVER_ADDRESS, Config.PORT);

Log.info("SocketSender connected.");

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

while(true) {

if(!messageQueue.isEmpty()) {

synchronized (messageQueue) {

sendMessage(messageQueue.poll());

}

}

if(in.available() > 0) {

byte[] msg = readMessage();

if(msg.length > 0){

Controller.getInstance().processMessage(msg);

}

}

}

}

開發者ID:DesktopRemoteManagement,項目名稱:DRM-Desktop,代碼行數:23,

示例7: run

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

@Override

public void run() {

try {

Socket socket = new Socket("127.0.0.1", 3123);

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

while(true) {

if(in.available() > 0) {

readMessage();

} else {

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

開發者ID:DesktopRemoteManagement,項目名稱:DRM-Desktop,代碼行數:19,

示例8: PRUDPPacketReplyError

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

protected

PRUDPPacketReplyError(

DataInputStreamis,

inttrans_id )

throws IOException

{

super( PRUDPPacketTracker.ACT_REPLY_ERROR, trans_id );

intavail = is.available();

byte[]data = new byte[avail];

is.read( data );

message= new String( data );

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:18,

示例9: readCountryFromAsset

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

public static String readCountryFromAsset(Context context, String assetName) {

String content = "";

try {

InputStream is = context.getAssets().open(assetName);

if (is == null) {

return content;

}

DataInputStream dIs = new DataInputStream(is);

byte[] buffer = new byte[dIs.available()];

dIs.read(buffer);

content = EncodingUtils.getString(buffer, "UTF-8");

is.close();

return content;

} catch (IOException e) {

e.printStackTrace();

return content;

}

}

開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,

示例10: PRUDPPacketReplyAnnounce2

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

protected

PRUDPPacketReplyAnnounce2(

DataInputStreamis,

inttrans_id )

throws IOException

{

super( PRUDPPacketTracker.ACT_REPLY_ANNOUNCE, trans_id );

interval = is.readInt();

leechers = is.readInt();

seeders = is.readInt();

addresses = new int[is.available()/BYTES_PER_ENTRY];

ports= new short[addresses.length];

for (int i=0;i

addresses[i] = is.readInt();

ports[i]= is.readShort();

}

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:23,

示例11: call

​點讚 3

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(FTABLE_NAME);

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,代碼行數:21,

示例12: PRUDPPacketReplyAnnounce

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

protected

PRUDPPacketReplyAnnounce(

DataInputStreamis,

inttrans_id )

throws IOException

{

super( PRUDPPacketTracker.ACT_REPLY_ANNOUNCE, trans_id );

interval = is.readInt();

addresses = new int[is.available()/BYTES_PER_ENTRY];

ports= new short[addresses.length];

for (int i=0;i

addresses[i] = is.readInt();

ports[i]= is.readShort();

}

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:21,

示例13: PRUDPPacketReplyScrape

​點讚 3

import java.io.DataInputStream; //導入方法依賴的package包/類

protected

PRUDPPacketReplyScrape(

DataInputStreamis,

inttrans_id )

throws IOException

{

super( PRUDPPacketTracker.ACT_REPLY_SCRAPE, trans_id );

// interval = is.readInt();

hashes = new byte[is.available()/BYTES_PER_ENTRY][];

complete= new int[hashes.length];

incomplete= new int[hashes.length];

downloaded= new int[hashes.length];

for (int i=0;i

hashes[i] = new byte[20];

is.read(hashes[i]);

complete[i] = is.readInt();

downloaded[i] = is.readInt();

incomplete[i] = is.readInt();

}

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:26,

示例14: readMultiLevelIndexRoot

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

/**

* Read the root-level metadata of a multi-level block index. Based on

* {@link #readRootIndex(DataInput, int)}, but also reads metadata

* necessary to compute the mid-key in a multi-level index.

*

* @param blk the HFile block

* @param numEntries the number of root-level index entries

* @throws IOException

*/

public void readMultiLevelIndexRoot(HFileBlock blk,

final int numEntries) throws IOException {

DataInputStream in = readRootIndex(blk, numEntries);

// after reading the root index the checksum bytes have to

// be subtracted to know if the mid key exists.

int checkSumBytes = blk.totalChecksumBytes();

if ((in.available() - checkSumBytes) < MID_KEY_METADATA_SIZE) {

// No mid-key metadata available.

return;

}

midLeafBlockOffset = in.readLong();

midLeafBlockOnDiskSize = in.readInt();

midKeyEntry = in.readInt();

}

開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,

示例15: getCode

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

/**

* Get shader from file.

*/

public CharSequence getCode(InputStream is) throws IOException {

final DataInputStream dataStream = new DataInputStream(is);

byte[] shaderCode = new byte[dataStream.available()];

dataStream.readFully(shaderCode);

return new String(shaderCode);

}

開發者ID:shaunlebron,項目名稱:flex-fov,代碼行數:10,

示例16: postDeserialise

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

protected void

postDeserialise(

DataInputStreamis )

throws IOException

{

if ( protocol_version < DHTTransportUDP.PROTOCOL_VERSION_FIX_ORIGINATOR ){

if ( is.available() > 0 ){

originator_version= is.readByte();

}else{

originator_version = protocol_version;

}

// if the originator is a higher version than us then we can't do anything sensible

// working at their version (e.g. we can't reply to them using that version).

// Therefore trim their perceived version back to something we can deal with

if ( originator_version > getTransport().getProtocolVersion() ){

originator_version = getTransport().getProtocolVersion();

}

}

}

開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:28,

示例17: deserializeFromPB

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

/**

* Deserialize the file trailer as protobuf

* @param inputStream

* @throws IOException

*/

void deserializeFromPB(DataInputStream inputStream) throws IOException {

// read PB and skip padding

int start = inputStream.available();

HFileProtos.FileTrailerProto trailerProto =

HFileProtos.FileTrailerProto.PARSER.parseDelimitedFrom(inputStream);

int size = start - inputStream.available();

inputStream.skip(getTrailerSize() - NOT_PB_SIZE - size);

// process the PB

if (trailerProto.hasFileInfoOffset()) {

fileInfoOffset = trailerProto.getFileInfoOffset();

}

if (trailerProto.hasLoadOnOpenDataOffset()) {

loadOnOpenDataOffset = trailerProto.getLoadOnOpenDataOffset();

}

if (trailerProto.hasUncompressedDataIndexSize()) {

uncompressedDataIndexSize = trailerProto.getUncompressedDataIndexSize();

}

if (trailerProto.hasTotalUncompressedBytes()) {

totalUncompressedBytes = trailerProto.getTotalUncompressedBytes();

}

if (trailerProto.hasDataIndexCount()) {

dataIndexCount = trailerProto.getDataIndexCount();

}

if (trailerProto.hasMetaIndexCount()) {

metaIndexCount = trailerProto.getMetaIndexCount();

}

if (trailerProto.hasEntryCount()) {

entryCount = trailerProto.getEntryCount();

}

if (trailerProto.hasNumDataIndexLevels()) {

numDataIndexLevels = trailerProto.getNumDataIndexLevels();

}

if (trailerProto.hasFirstDataBlockOffset()) {

firstDataBlockOffset = trailerProto.getFirstDataBlockOffset();

}

if (trailerProto.hasLastDataBlockOffset()) {

lastDataBlockOffset = trailerProto.getLastDataBlockOffset();

}

if (trailerProto.hasComparatorClassName()) {

// TODO this is a classname encoded into an HFile's trailer. We are going to need to have

// some compat code here.

setComparatorClass(getComparatorClass(trailerProto.getComparatorClassName()));

}

if (trailerProto.hasCompressionCodec()) {

compressionCodec = Compression.Algorithm.values()[trailerProto.getCompressionCodec()];

} else {

compressionCodec = Compression.Algorithm.NONE;

}

if (trailerProto.hasEncryptionKey()) {

encryptionKey = trailerProto.getEncryptionKey().toByteArray();

}

}

開發者ID:fengchen8086,項目名稱:ditb,代碼行數:59,

示例18: processChunk

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

/**

* @param msg

* @return true if done processing

*/

boolean processChunk(RemoteFetchKeysReplyMessage msg) {

// this processing algorighm won't work well if there are multiple recipients. currently the

// retry logic for failed recipients is in PartitionedRegion. If we parallelize the sending

// of this message, we'll need to handle failover in this processor class and track results

// differently.

boolean doneProcessing = false;

try {

ByteArrayInputStream byteStream = new ByteArrayInputStream(msg.chunk);

DataInputStream in = new DataInputStream(byteStream);

while (in.available() > 0) {

Object key = DataSerializer.readObject(in);

if (key != null) {

synchronized (returnValue) {

returnValue.add(key);

}

} else {

// null should signal the end of the set of keys

Assert.assertTrue(in.available() == 0);

}

}

synchronized (this.endLock) {

chunksProcessed = chunksProcessed + 1;

if (((msg.seriesNum + 1) == msg.numSeries) && msg.lastInSeries) {

lastChunkReceived = true;

chunksExpected = msg.msgNum + 1;

}

if (lastChunkReceived && (chunksExpected == chunksProcessed)) {

doneProcessing = true;

}

if (logger.isTraceEnabled(LogMarker.DM)) {

logger.trace(LogMarker.DM,

"{} chunksProcessed={},lastChunkReceived={},chunksExpected={},done={}", this,

chunksProcessed, lastChunkReceived, chunksExpected, doneProcessing);

}

}

} catch (Exception e) {

processException(new ReplyException(

LocalizedStrings.FetchKeysMessage_ERROR_DESERIALIZING_KEYS.toLocalizedString(), e));

}

return doneProcessing;

}

開發者ID:ampool,項目名稱:monarch,代碼行數:51,

示例19: processChunk

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

void processChunk(FetchKeysReplyMessage msg) {

// this processing algorighm won't work well if there are multiple recipients. currently the

// retry logic for failed recipients is in PartitionedRegion. If we parallelize the sending

// of this message, we'll need to handle failover in this processor class and track results

// differently.

boolean doneProcessing = false;

if (msg.getException() != null) {

process(msg);

} else {

try {

ByteArrayInputStream byteStream = new ByteArrayInputStream(msg.chunk);

DataInputStream in = new DataInputStream(byteStream);

while (in.available() > 0) {

Object key = DataSerializer.readObject(in);

if (key != null) {

synchronized (returnValue) {

returnValue.add(key);

}

} else {

// null should signal the end of the set of keys

Assert.assertTrue(in.available() == 0);

}

}

synchronized (this.endLock) {

chunksProcessed = chunksProcessed + 1;

if (((msg.seriesNum + 1) == msg.numSeries) && msg.lastInSeries) {

lastChunkReceived = true;

chunksExpected = msg.msgNum + 1;

}

if (lastChunkReceived && (chunksExpected == chunksProcessed)) {

doneProcessing = true;

}

if (logger.isTraceEnabled(LogMarker.DM)) {

logger.debug("{} chunksProcessed={},lastChunkReceived={},chunksExpected={},done={}",

this, chunksProcessed, lastChunkReceived, chunksExpected, doneProcessing);

}

}

} catch (Exception e) {

processException(new ReplyException(

LocalizedStrings.FetchKeysMessage_ERROR_DESERIALIZING_KEYS.toLocalizedString(), e));

checkIfDone(); // fix for hang in 41202

}

// if all chunks have been received, wake up the waiting thread

if (doneProcessing) {

process(msg);

}

}

}

開發者ID:ampool,項目名稱:monarch,代碼行數:55,

示例20: doRead

​點讚 2

import java.io.DataInputStream; //導入方法依賴的package包/類

private void doRead(File file, boolean readOldFormat) {

IOException e;

Throwable th;

DataInputStream dataInputStream = null;

try {

this.id2size = new HashMapIntLong(((int) file.length()) / 8);

DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));

while (in.available() > 0) {

try {

int key = in.readInt();

long value = in.readLong();

if (value < 0 && readOldFormat) {

value = -(value - -9223372036854775807L);

}

this.id2size.put(key, value);

} catch (IOException e2) {

e = e2;

dataInputStream = in;

} catch (Throwable th2) {

th = th2;

dataInputStream = in;

}

}

if (in != null) {

try {

in.close();

} catch (IOException e3) {

}

}

if (null != null) {

try {

file.delete();

} catch (RuntimeException e4) {

dataInputStream = in;

return;

}

}

dataInputStream = in;

} catch (IOException e5) {

e = e5;

try {

Logger.getLogger(RetainedSizeCache.class.getName()).log(Level.WARNING, Messages.RetainedSizeCache_ErrorReadingRetainedSizes.pattern, e);

this.id2size.clear();

if (dataInputStream != null) {

try {

dataInputStream.close();

} catch (IOException e6) {

}

}

if (true) {

try {

file.delete();

} catch (RuntimeException e7) {

}

}

} catch (Throwable th3) {

th = th3;

if (dataInputStream != null) {

try {

dataInputStream.close();

} catch (IOException e8) {

}

}

if (null != null) {

try {

file.delete();

} catch (RuntimeException e9) {

}

}

throw th;

}

}

}

開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:74,

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

转载地址:http://radqv.baihongyu.com/

你可能感兴趣的文章
Swift的高级分享 - Swift中的逻辑控制器
查看>>
Swagger简单介绍
查看>>
Python数据分析入门案例
查看>>
vue-devtools 获取到 vuex store 和 Vue 实例的?
查看>>
Linux 中【./】和【/】和【.】之间有什么区别?
查看>>
内存地址对齐
查看>>
看门狗 (监控芯片)
查看>>
#ifndef #define #endif
查看>>
css背景样式
查看>>
JavaScript介绍
查看>>
开源网络漏洞扫描软件
查看>>
yum 命令跳过特定(指定)软件包升级方法
查看>>
创新课程管理系统数据库设计心得
查看>>
Hallo wolrd!
查看>>
16下学期进度条2
查看>>
Could not resolve view with name '***' in servlet with name 'dispatcher'
查看>>
Chapter 3 Phenomenon——12
查看>>
C语言中求最大最小值的库函数
查看>>
和小哥哥一起刷洛谷(1)
查看>>
jquery对id中含有特殊字符的转义处理
查看>>