本文整理汇总了Java中java.io.DataInputStream.readInt方法的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream.readInt方法的具体用法?Java DataInputStream.readInt怎么用?Java DataInputStream.readInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataInputStream
的用法示例。
在下文中一共展示了DataInputStream.readInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readOtherCurrencies
import java.io.DataInputStream; //导入方法依赖的package包/类
private static List<OtherCurrencyEntry> readOtherCurrencies(DataInputStream dis,
int count)
throws IOException {
List<OtherCurrencyEntry> list = new ArrayList<>(count);
String currencyCode;
int fraction;
int numericCode;
for (int i = 0; i < count; i++) {
currencyCode = dis.readUTF();
fraction = dis.readInt();
numericCode = dis.readInt();
OtherCurrencyEntry oc = new OtherCurrencyEntry(currencyCode,
fraction,
numericCode);
list.add(oc);
}
return list;
}
示例2: call
import java.io.DataInputStream; //导入方法依赖的package包/类
public Peer call() {
try {
Socket clientSocket = new Socket(peer.getAddress(),peer.getPeerHeartBeatPort());
DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
DataInputStream in = new DataInputStream(clientSocket.getInputStream());
out.writeInt(Config.HEARTBEAT_FLAG_SERVER); //0 for heartbeats
out.flush();
clientSocket.setSoTimeout(Config.HEARTBEAT_TIMEOUT);
int x = in.readInt();
if(x == Config.HEARTBEAT_ACK) {
return peer;
}
} catch (IOException e) {
return null;
}
return null;
}
示例3: rllong
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* rllong
* Protected helper method to read 64 bits and changing the order of
* each bytes.
*
* @param DataInputStream
* @return 32 bits swapped value.
* @throws IOException
*/
protected int rllong(DataInputStream dis) throws IOException {
int b1, b2, b3, b4;
int i = 0;
i = dis.readInt();
b1 = (i & 0xFF) << 24;
b2 = (i & 0xFF00) << 8;
b3 = (i & 0xFF0000) >> 8;
b4 = (i & 0xFF000000) >>> 24;
i = (b1 | b2 | b3 | b4);
return i;
}
示例4: readBlocks
import java.io.DataInputStream; //导入方法依赖的package包/类
private static Block[] readBlocks(
DataInputStream in,
int logVersion) throws IOException {
int numBlocks = in.readInt();
if (numBlocks < 0) {
throw new IOException("invalid negative number of blocks");
} else if (numBlocks > MAX_BLOCKS) {
throw new IOException("invalid number of blocks: " + numBlocks +
". The maximum number of blocks per file is " + MAX_BLOCKS);
}
Block[] blocks = new Block[numBlocks];
for (int i = 0; i < numBlocks; i++) {
Block blk = new Block();
blk.readFields(in);
blocks[i] = blk;
}
return blocks;
}
示例5: read
import java.io.DataInputStream; //导入方法依赖的package包/类
@Override
public void read(DataInputStream in) throws IOException {
final int version = in.readInt();
switch (version) {
case VERSION_INIT:
throw new ProtocolException("Ignored upgrade");
case VERSION_SPLIT_URI:
authority = DurableUtils.readNullableString(in);
documentId = DurableUtils.readNullableString(in);
mimeType = DurableUtils.readNullableString(in);
displayName = DurableUtils.readNullableString(in);
lastModified = in.readLong();
flags = in.readInt();
summary = DurableUtils.readNullableString(in);
size = in.readLong();
icon = in.readInt();
path = DurableUtils.readNullableString(in);
deriveFields();
break;
default:
throw new ProtocolException("Unknown version " + version);
}
}
示例6: validateData
import java.io.DataInputStream; //导入方法依赖的package包/类
private void validateData(DataInputStream in) throws IOException {
// validate data
for (int i = 0; i < 1234; i++) {
int val = in.readInt();
assertEquals("testChecksumCorruption: data mismatch at index " + i, i, val);
}
}
示例7: run
import java.io.DataInputStream; //导入方法依赖的package包/类
public void run() throws Exception {
DataInputStream instr = new DataInputStream(new EncodedStream.EncodedInput(System.in));
// Read shared packages
int sharedPackagesCount = instr.readInt();
List<String> sharedPackages = new ArrayList<String>(sharedPackagesCount);
for (int i = 0; i < sharedPackagesCount; i++) {
sharedPackages.add(instr.readUTF());
}
// Read worker implementation classpath
int classPathLength = instr.readInt();
URL[] implementationClassPath = new URL[classPathLength];
for (int i = 0; i < classPathLength; i++) {
String url = instr.readUTF();
implementationClassPath[i] = new URL(url);
}
// Set up worker ClassLoader
FilteringClassLoader.Spec filteringClassLoaderSpec = new FilteringClassLoader.Spec();
for (String sharedPackage : sharedPackages) {
filteringClassLoaderSpec.allowPackage(sharedPackage);
}
FilteringClassLoader filteringClassLoader = new FilteringClassLoader(getClass().getClassLoader(), filteringClassLoaderSpec);
URLClassLoader classLoader = new URLClassLoader(implementationClassPath, filteringClassLoader);
Class<? extends Callable> workerClass = classLoader.loadClass("org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker").asSubclass(Callable.class);
Callable<Void> main = workerClass.getConstructor(DataInputStream.class).newInstance(instr);
main.call();
}
示例8: compareDirs
import java.io.DataInputStream; //导入方法依赖的package包/类
static boolean compareDirs(DataInputStream is) throws IOException {
int cnt = is.readInt();
String[] arr = relativeDirsWithHome();
if (cnt != arr.length) {
return false;
}
for (int i = 0; i < arr.length; i++) {
String cluster = is.readUTF();
if (!cluster.equals(arr[i])) {
return false;
}
}
return true;
}
示例9: load
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* Load partition from model file.
*
* @param input the input
* @throws IOException
*/
public void load(DataInputStream input) throws IOException {
try {
int size = input.readInt();
for (int i = 0; i < size; i ++) {
int rowId = input.readInt();
ServerRow serverRow = rows.get(rowId);
serverRow.readFrom(input);
}
} finally {
setState(PartitionState.READ_AND_WRITE);
}
}
示例10: readIntArray
import java.io.DataInputStream; //导入方法依赖的package包/类
private static int[] readIntArray(DataInputStream dis, int count) throws IOException {
int[] ret = new int[count];
for (int i = 0; i < count; i++) {
ret[i] = dis.readInt();
}
return ret;
}
示例11: transactionReceived
import java.io.DataInputStream; //导入方法依赖的package包/类
public void transactionReceived(Transaction transaction, Object transactionObject) throws BadPacketException {
try {
DataInputStream in = new DataInputStream(
new ByteArrayInputStream(transaction.getData()));
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOutputStream);
MysterType type = new MysterType(in.readInt());
String filename = in.readUTF();
FileItem fileItem = FileTypeListManager.getInstance().getFileItem(type, filename);
MML mml;
if (fileItem == null) { //file not found
mml = new MML();
} else {
mml = fileItem.getMMLRepresentation();
}
out.writeUTF(mml.toString());
sendTransaction(new Transaction(transaction, byteOutputStream.toByteArray(),
Transaction.NO_ERROR));
} catch (IOException ex) {
throw new BadPacketException("Bad packet " + ex);
}
}
示例12: connect
import java.io.DataInputStream; //导入方法依赖的package包/类
public static void connect(com.badlogic.gdx.net.Socket gdxSocket) throws Exception {
Socket javaSocket = extractJavaSocket(gdxSocket);
DataOutputStream dataOutputStream = new DataOutputStream(javaSocket.getOutputStream());
dataOutputStream.writeByte(0); //0 is connect
javaSocket.setSoTimeout(TIMEOUT);
int serverMajor;
int serverMinor;
int serverPoint;
int serverBuild;
String serverHash;
try {
DataInputStream dataInputStream = new DataInputStream(javaSocket.getInputStream());
serverMajor = dataInputStream.readInt();
serverMinor = dataInputStream.readInt();
serverPoint = dataInputStream.readInt();
serverBuild = dataInputStream.readInt();
serverHash = dataInputStream.readUTF();
} catch (IOException e) {
if (e instanceof SocketTimeoutException) {
throw new IOException("Server did not respond in time", e);
} else {
throw e;
}
}
if (serverMajor == Branding.VERSION_MAJOR && serverMinor == Branding.VERSION_MINOR && serverPoint == Branding.VERSION_POINT) {
if (serverBuild == Branding.VERSION_BUILD) {
if (!serverHash.equals(Branding.VERSION_HASH)) {
Log.warning("Server reports the same build, but has a different hash");
} else {
Log.debug("Server is running exactly the same build");
}
} else {
Log.warning("Server is running build " + serverBuild);
}
} else {
String str = serverMajor + "." + serverMinor + "." + serverPoint;
throw new IOException("Server is running version " + str + " not " + Branding.VERSION_MAJOR_MINOR_POINT);
}
javaSocket.setSoTimeout(0);
}
示例13: getArgs
import java.io.DataInputStream; //导入方法依赖的package包/类
private String[] getArgs(DataInputStream in) throws IOException {
String[] args = new String[in.readInt()];
for (int i = 0; i < args.length; i++) {
args[i] = in.readUTF();
}
return args;
}
示例14: DHTUDPPacketReplyStats
import java.io.DataInputStream; //导入方法依赖的package包/类
protected
DHTUDPPacketReplyStats(
DHTUDPPacketNetworkHandler network_handler,
InetSocketAddress originator,
DataInputStream is,
int trans_id )
throws IOException
{
super( network_handler, originator, is, DHTUDPPacketHelper.ACT_REPLY_STATS, trans_id );
if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_GENERIC_NETPOS ){
stats_type = is.readInt();
if ( stats_type == DHTUDPPacketRequestStats.STATS_TYPE_ORIGINAL ){
original_stats = DHTUDPUtils.deserialiseStats( getProtocolVersion(), is );
}else{
new_stats = DHTUDPUtils.deserialiseByteArray( is, 65535 );
}
}else{
original_stats = DHTUDPUtils.deserialiseStats( getProtocolVersion(), is );
}
}
示例15: load
import java.io.DataInputStream; //导入方法依赖的package包/类
@Override
public void load(DataInputStream in) throws IOException
{
super.load(in);
typeSelect.load(in);
listenButton.load(in);
controller = in.readInt();
controllerBox.setText(Integer.toString(controller));
}