List of usage examples for java.io DataInputStream readInt
public final int readInt() throws IOException
readInt
method of DataInput
. From source file:org.eredlab.g4.ccl.net.TimeTCPClient.java
/*** * Retrieves the time from the server and returns it. The time * is the number of seconds since 00:00 (midnight) 1 January 1900 GMT, * as specified by RFC 868. This method reads the raw 32-bit big-endian * unsigned integer from the server, converts it to a Java long, and * returns the value.// w ww.j av a 2 s.com * <p> * The server will have closed the connection at this point, so you should * call * {@link org.apache.commons.net.SocketClient#disconnect disconnect } * after calling this method. To retrieve another time, you must * initiate another connection with * {@link org.apache.commons.net.SocketClient#connect connect } * before calling <code> getTime() </code> again. * <p> * @return The time value retrieved from the server. * @exception IOException If an error occurs while fetching the time. ***/ public long getTime() throws IOException { DataInputStream input; input = new DataInputStream(_input_); return (long) (input.readInt() & 0xffffffffL); }
From source file:org.getspout.spout.packet.PacketBlockData.java
public void readData(DataInputStream input) throws IOException { int size = input.readInt(); compressed = input.readBoolean();/* ww w . j a va 2 s.c o m*/ if (size > 0) { data = new byte[size]; input.readFully(data); } }
From source file:org.getspout.spout.packet.PacketCustomBlockChunkOverride.java
public void readData(DataInputStream input) throws IOException { chunkX = input.readInt(); chunkZ = input.readInt();//from w ww. java 2 s . c o m int size = input.readInt(); data = new byte[size]; input.readFully(data); }
From source file:net.brtly.monkeyboard.plugin.core.panel.PluginDockableLayout.java
@Override public void readStream(DataInputStream in) throws IOException { _id = in.readUTF(); // get the plugin ID int bs = in.readInt(); // get the size, in bytes, of the Bundle byte[] b = new byte[bs]; // read the Bundle in.read(b);//from ww w.ja v a2 s. co m }
From source file:org.apache.cassandra.db.RangeCommand.java
public RangeCommand deserialize(DataInputStream dis) throws IOException { return new RangeCommand(dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readUTF(), dis.readInt()); }
From source file:org.openmrs.module.odkconnector.serialization.serializer.openmrs.CohortSerializerTest.java
@Test public void serialize_shouldSerializeCohortInformation() throws Exception { CohortService cohortService = Context.getCohortService(); Cohort firstCohort = new Cohort(); firstCohort.addMember(6);//from www .ja v a 2s.c o m firstCohort.addMember(7); firstCohort.addMember(8); firstCohort.setName("First Cohort"); firstCohort.setDescription("First cohort for testing the serializer"); cohortService.saveCohort(firstCohort); Cohort secondCohort = new Cohort(); secondCohort.addMember(6); secondCohort.addMember(7); secondCohort.addMember(8); secondCohort.setName("Second Cohort"); secondCohort.setDescription("Second cohort for testing the serializer"); cohortService.saveCohort(secondCohort); File file = File.createTempFile("CohortSerialization", "Example"); GZIPOutputStream outputStream = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(file))); List<Cohort> cohorts = cohortService.getAllCohorts(); Serializer serializer = HandlerUtil.getPreferredHandler(Serializer.class, List.class); serializer.write(outputStream, cohorts); outputStream.close(); GZIPInputStream inputStream = new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))); DataInputStream dataInputStream = new DataInputStream(inputStream); Integer cohortCounts = dataInputStream.readInt(); System.out.println("Number of cohorts: " + cohortCounts); for (int i = 0; i < cohortCounts; i++) { System.out.println("Cohort ID: " + dataInputStream.readInt()); System.out.println("Cohort Name: " + dataInputStream.readUTF()); } inputStream.close(); }
From source file:org.apache.fop.afp.apps.FontPatternExtractor.java
/** * Extracts the Type1 PFB file from the given AFP outline font. * @param file the AFP file to read from * @param targetDir the target directory where the PFB file is to be placed. * @throws IOException if an I/O error occurs *///from www. java 2 s .co m public void extract(File file, File targetDir) throws IOException { InputStream in = new java.io.FileInputStream(file); try { MODCAParser parser = new MODCAParser(in); ByteArrayOutputStream baout = new ByteArrayOutputStream(); UnparsedStructuredField strucField; while ((strucField = parser.readNextStructuredField()) != null) { if (strucField.getSfTypeID() == 0xD3EE89) { byte[] sfData = strucField.getData(); println(strucField.toString()); HexDump.dump(sfData, 0, printStream, 0); baout.write(sfData); } } ByteArrayInputStream bin = new ByteArrayInputStream(baout.toByteArray()); DataInputStream din = new DataInputStream(bin); long len = din.readInt() & 0xFFFFFFFFL; println("Length: " + len); din.skip(4); //checksum int tidLen = din.readUnsignedShort() - 2; byte[] tid = new byte[tidLen]; din.readFully(tid); String filename = new String(tid, "ISO-8859-1"); int asciiCount1 = countUSAsciiCharacters(filename); String filenameEBCDIC = new String(tid, "Cp1146"); int asciiCount2 = countUSAsciiCharacters(filenameEBCDIC); println("TID: " + filename + " " + filenameEBCDIC); if (asciiCount2 > asciiCount1) { //Haven't found an indicator if the name is encoded in EBCDIC or not //so we use a trick. filename = filenameEBCDIC; } if (!filename.toLowerCase().endsWith(".pfb")) { filename = filename + ".pfb"; } println("Output filename: " + filename); File out = new File(targetDir, filename); OutputStream fout = new java.io.FileOutputStream(out); try { IOUtils.copyLarge(din, fout); } finally { IOUtils.closeQuietly(fout); } } finally { IOUtils.closeQuietly(in); } }
From source file:org.spoutcraft.client.packet.PacketEntityInformation.java
public void readData(DataInputStream input) throws IOException { int size = input.readInt(); if (size > 0) { data = new byte[size]; input.readFully(data);//from w ww . j a va2 s.c om } compressed = input.readBoolean(); }
From source file:org.hydracache.server.data.versioning.VectorClockVersionFactory.java
@Override public Version readObject(final DataInputStream dataIn) throws IOException { Validate.notNull(dataIn, "dataIn can not be null"); final int entriesCount = dataIn.readInt(); final List<VectorClockEntry> vectorClockEntries = new ArrayList<VectorClockEntry>(); for (int i = 0; i < entriesCount; i++) { final Identity nodeId = getIdentityMarshaller().readObject(dataIn); final long value = dataIn.readLong(); final long timeStamp = dataIn.readLong(); vectorClockEntries.add(new VectorClockEntry(nodeId, value, timeStamp)); }/*from w w w. j a v a2 s . c o m*/ return new VectorClock(vectorClockEntries); }
From source file:org.openmrs.module.odkconnector.serialization.web.CohortWebConnectorTest.java
@Test public void serialize_shouldDisplayAllCohortInformation() throws Exception { // compose url URL u = new URL(SERVER_URL + "/module/odkconnector/download/cohort.form"); // setup http url connection HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setDoOutput(true);/*from w w w . j a v a2 s.c om*/ connection.setRequestMethod("POST"); connection.setConnectTimeout(8000); connection.setReadTimeout(8000); connection.addRequestProperty("Content-type", "application/octet-stream"); // write auth details to connection DataOutputStream outputStream = new DataOutputStream(new GZIPOutputStream(connection.getOutputStream())); outputStream.writeUTF("admin"); outputStream.writeUTF("test"); outputStream.writeBoolean(false); outputStream.close(); DataInputStream inputStream = new DataInputStream(new GZIPInputStream(connection.getInputStream())); Integer responseStatus = inputStream.readInt(); if (responseStatus == HttpURLConnection.HTTP_OK) { Integer cohortCounts = inputStream.readInt(); System.out.println("Number of cohorts: " + cohortCounts); for (int i = 0; i < cohortCounts; i++) { System.out.println("Cohort ID: " + inputStream.readInt()); System.out.println("Cohort Name: " + inputStream.readUTF()); } } inputStream.close(); }