本文整理汇总了Java中java.io.DataInputStream.available方法的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream.available方法的具体用法?Java DataInputStream.available怎么用?Java DataInputStream.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataInputStream
的用法示例。
在下文中一共展示了DataInputStream.available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
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<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);
}
}
示例2: stream
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;
}
示例3: PRUDPPacketReplyScrape2
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketReplyScrape2(
DataInputStream is,
int trans_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.length;i++){
complete[i] = is.readInt();
downloaded[i] = is.readInt();
incomplete[i] = is.readInt();
}
}
示例4: getClassBody
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;
}
示例5: internalDecodeKeyValues
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;
}
示例6: tryConnect
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);
}
}
}
}
示例7: run
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();
}
}
示例8: PRUDPPacketReplyError
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketReplyError(
DataInputStream is,
int trans_id )
throws IOException
{
super( PRUDPPacketTracker.ACT_REPLY_ERROR, trans_id );
int avail = is.available();
byte[] data = new byte[avail];
is.read( data );
message = new String( data );
}
示例9: readCountryFromAsset
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;
}
}
示例10: PRUDPPacketReplyAnnounce2
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketReplyAnnounce2(
DataInputStream is,
int trans_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.length;i++){
addresses[i] = is.readInt();
ports[i] = is.readShort();
}
}
示例11: 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(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;
}
示例12: PRUDPPacketReplyAnnounce
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketReplyAnnounce(
DataInputStream is,
int trans_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.length;i++){
addresses[i] = is.readInt();
ports[i] = is.readShort();
}
}
示例13: PRUDPPacketReplyScrape
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketReplyScrape(
DataInputStream is,
int trans_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.length;i++){
hashes[i] = new byte[20];
is.read(hashes[i]);
complete[i] = is.readInt();
downloaded[i] = is.readInt();
incomplete[i] = is.readInt();
}
}
示例14: readMultiLevelIndexRoot
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();
}
示例15: getCode
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);
}