Java Code Examples for java.io.DataInputStream.readInt()

The following are Jave code examples for showing how to use readInt() of the java.io.DataInputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: Currency.java   View Source Code Vote up 7 votes
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;
}
 
Example 2
Project: CrypDist   File: HeartBeatTask.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: MARF-for-Android   File: SunFileReader.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 4
Project: hadoop   File: FSEditLogOp.java   View Source Code Vote up 6 votes
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;
}
 
Example 5
Project: FireFiles   File: DocumentInfo.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 6
Project: ditb   File: TestChecksum.java   View Source Code Vote up 5 votes
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);
  }
}
 
Example 7
Project: Reer   File: GradleWorkerMain.java   View Source Code Vote up 5 votes
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();
}
 
Example 8
Project: incubator-netbeans   File: Clusters.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: angel   File: ServerPartition.java   View Source Code Vote up 5 votes
/**
 * 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);
  }
}
 
Example 10
Project: OpenJSharp   File: Currency.java   View Source Code Vote up 5 votes
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;
}
 
Example 11
Project: myster   File: FileStatsDatagramServer.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 12
Project: Cubes   File: ClientConnectionInitializer.java   View Source Code Vote up 5 votes
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);
}
 
Example 13
Project: myster   File: ApplicationSingleton.java   View Source Code Vote up 5 votes
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;
}
 
Example 14
Project: BiglyBT   File: DHTUDPPacketReplyStats.java   View Source Code Vote up 5 votes
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 );
	}
}
 
Example 15
Project: KraftigAudio   File: MidiDecoder.java   View Source Code Vote up 5 votes
@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));
}
 
Example 16
Project: Cubeland   File: BlockMetaData.java   View Source Code Vote up 5 votes
public final BlockMetaData load( DataInputStream in, String type ) throws IOException {
	Vector3i tmpPosition = new Vector3i();
	tmpPosition.x = in.readInt();
	tmpPosition.y = in.readInt();
	tmpPosition.z = in.readInt();
	BlockMetaData tmp = loadNew(in);
	tmp.type = type;
	tmp.position = tmpPosition;
	return tmp;
}
 
Example 17
Project: hadoop   File: TestCodec.java   View Source Code Vote up 4 votes
private static int readLeadingInt(Text txt) throws IOException {
  DataInputStream in =
    new DataInputStream(new ByteArrayInputStream(txt.getBytes()));
  return in.readInt();
}
 
Example 18
Project: incubator-netbeans   File: DatabaseDefinition.java   View Source Code Vote up 4 votes
public static DatabaseDefinition load (DataInputStream is) throws IOException {
    return new DatabaseDefinition (is.readUTF (), is.readUTF (), is.readInt (), is.readInt ());
}
 
Example 19
Project: boohee_v5.6   File: RetainedSizeCache.java   View Source Code Vote up 4 votes
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;
        }
    }
}
 
Example 20
Project: Cubes   File: PacketAreaUpdateRender.java   View Source Code Vote up 4 votes
@Override
public void read(DataInputStream dataInputStream) throws Exception {
  areaX = dataInputStream.readInt();
  areaZ = dataInputStream.readInt();
  ySection = dataInputStream.readInt();
}