java socket datainputstream_Java DataInputStream.available方法代碼示例

本文详细介绍了Java中DataInputStream.available()方法的常见应用场景,并提供了多个示例代码,包括从文件读取、网络通信和数据处理等方面。通过这些示例,读者可以了解如何检查输入流中可用的数据量,以及在不同上下文中如何有效地使用该方法。
摘要由CSDN通过智能技术生成

本文整理匯總了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();

w

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值