import java.io.DataInputStream; DataInputStream dis = new DataInputStream(System.in); int i = dis.readInt();
private boolean checkMagic(File file, long magic) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try { int m = in.readInt(); return magic == m; } finally { in.close(); } }
byte[] test = new byte[] {0, 0, 1, 0, 0, 0, 1, 1, 8, 9}; DataInputStream stream = new DataInputStream(new ByteArrayInputStream(test)); int value0 = stream.readInt(); int value1 = stream.readInt(); byte value2 = stream.readByte(); byte value3 = stream.readByte(); stream.close(); System.out.println(value0 + " " + value1 + " " + value2 + " " + value3);
public static int[] getBits(byte[] mBytes) throws IOException { int bitSize = mBytes.length / 4; int[] bits = new int[bitSize]; DataInputStream dis = new DataInputStream(new ByteArrayInputStream(mBytes)); for (int i = 0; i < bitSize; i++) { bits[i] = dis.readInt(); } return bits; }
File file = new File("C:/text.bin"); DataInputStream stream = new DataInputStream(new FileInputStream(file)); boolean isTrue = stream.readBoolean(); int value = stream.readInt(); stream.close(); System.out.printlin(isTrue + " " + value);
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(decoded))) { String databaseName = in.readUTF(); String tableName = in.readUTF(); boolean createPartitions = in.readBoolean(); long writeId = in.readLong(); TableType tableType = TableType.valueOf(in.readByte()); int thriftLength = in.readInt(); try { byte[] thriftEncoded = new byte[thriftLength]; in.readFully(thriftEncoded, 0, thriftLength); new TDeserializer(new TCompactProtocol.Factory()).deserialize(metaTable, thriftEncoded); table.setTable(metaTable);
public void readState(InputStream instream) throws IOException { DataInputStream in=new DataInputStream(new BufferedInputStream(instream)); Map<Point,Color> new_state=new LinkedHashMap<>(); int num=in.readInt(); for(int i=0; i < num; i++) { Point point=new Point(in.readInt(), in.readInt()); Color col=new Color(in.readInt()); new_state.put(point, col); } synchronized(state) { state.clear(); state.putAll(new_state); System.out.println("read " + state.size() + " elements"); createOffscreenImage(true); } }
if (cacheExists()) { try ( DataInputStream inputStream = new DataInputStream( new BufferedInputStream(Files.newInputStream(cacheFile.toPath()))); ) { final String cacheVersion = inputStream.readUTF(); rulesetChecksum = inputStream.readLong(); auxClassPathChecksum = inputStream.readLong(); executionClassPathChecksum = inputStream.readLong(); final String fileName = inputStream.readUTF(); final long checksum = inputStream.readLong(); final int countViolations = inputStream.readInt(); final List<RuleViolation> violations = new ArrayList<>(countViolations); for (int i = 0; i < countViolations; i++) {
/** * Deserialize a bloom filter * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)} * into a {@code BloomKFilter} * * @param in input bytestream * * @return deserialized BloomKFilter */ public static BloomKFilter deserialize(InputStream in) throws IOException { if (in == null) { throw new IOException("Input stream is null"); } try { DataInputStream dataInputStream = new DataInputStream(in); int numHashFunc = dataInputStream.readByte(); int bitsetArrayLen = dataInputStream.readInt(); long[] data = new long[bitsetArrayLen]; for (int i = 0; i < bitsetArrayLen; i++) { data[i] = dataInputStream.readLong(); } return new BloomKFilter(data, numHashFunc); } catch (RuntimeException e) { IOException io = new IOException("Unable to deserialize BloomKFilter"); io.initCause(e); throw io; } }
if (in.readInt() != VERSION_0_FILE_MAGIC_NUMBER) { throw new Error("Invalid file version/magic number for stubx file!" + stubxLocation); int numStrings = in.readInt(); int numPackages = in.readInt(); in.readInt(); // String packageName = strings[in.readInt()]; in.readInt(); // String annotation = strings[in.readInt()]; int numTypes = in.readInt(); in.readInt(); // String typeName = strings[in.readInt()]; in.readInt(); // String annotation = strings[in.readInt()]; int numMethods = in.readInt(); String methodSig = strings[in.readInt()]; String annotation = strings[in.readInt()]; LOG(DEBUG, "DEBUG", "method: " + methodSig + ", return annotation: " + annotation); cacheAnnotation(methodSig, RETURN, annotation); int numArgumentRecords = in.readInt(); String methodSig = strings[in.readInt()]; if (methodSig.lastIndexOf(':') == -1 || methodSig.split(":")[0].lastIndexOf('.') == -1) { throw new Error( "Invalid method signature " + methodSig + " in stubx file " + stubxLocation);
/** get the major version of klass by loading the bytecode from source */ public static int getVersion(ClassLoader source,Class klass) { String cname = WeavingClassLoader.makeResourceName(klass.getName()); DataInputStream in = new DataInputStream(source.getResourceAsStream(cname)); try { int magic = in.readInt(); int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); in.close(); return major; } catch (IOException ex) { throw new RuntimeException(ex); } }
private void readHeaderToken() throws IOException { byte archiveVersion = dataIn.readByte(); if (archiveVersion <= 1) { throw new GemFireIOException( String.format("Archive version: %s is no longer supported.", new Byte(archiveVersion)), null); } if (archiveVersion > ARCHIVE_VERSION) { throw new GemFireIOException( String.format("Unsupported archive version: %s . The supported version is: %s .", new Object[] {new Byte(archiveVersion), new Byte(ARCHIVE_VERSION)}), null); } this.archiveVersion = archiveVersion; this.startTimeStamp = dataIn.readLong(); this.systemId = dataIn.readLong(); this.systemStartTimeStamp = dataIn.readLong(); this.timeZoneOffset = dataIn.readInt(); this.timeZoneName = dataIn.readUTF(); this.systemDirectory = dataIn.readUTF(); this.productVersion = dataIn.readUTF(); this.os = dataIn.readUTF(); this.machine = dataIn.readUTF(); }
public static SnappyCodec readHeader(InputStream in) throws IOException { DataInputStream d = new DataInputStream(in); byte[] magic = new byte[MAGIC_LEN]; d.readFully(magic, 0, MAGIC_LEN); int version = d.readInt(); int compatibleVersion = d.readInt(); return new SnappyCodec(magic, version, compatibleVersion); } }
@Override public Schema readSchema(InputStream in) throws IOException { DataInputStream dataInputStream = new DataInputStream(in); if (dataInputStream.readByte() != 0) { throw new IOException("Unknown data format. Magic number does not match"); } else { int schemaId = dataInputStream.readInt(); try { return schemaRegistryClient.getById(schemaId); } catch (RestClientException e) { throw new IOException(format("Could not find schema with id %s in registry", schemaId), e); } } }
@Override protected boolean listen(final InputStream in, final OutputStream out, final int version) throws IOException { final DataInputStream dis = new DataInputStream(in); final DataOutputStream dos = new DataOutputStream(out); final String action = dis.readUTF(); if (action.equals("close")) { return false; } final int valueLength = dis.readInt(); final byte[] value = new byte[valueLength]; dis.readFully(value); final ByteBuffer valueBuffer = ByteBuffer.wrap(value); final SetCacheResult response; switch (action) { case "addIfAbsent": response = cache.addIfAbsent(valueBuffer); break; case "contains": response = cache.contains(valueBuffer); break; case "remove": response = cache.remove(valueBuffer); break; default: throw new IOException("IllegalRequest"); } dos.writeBoolean(response.getResult()); dos.flush(); return true; }
private SnapshotHeader validateHeader(final DataInputStream dataIn) throws IOException { final String snapshotClass = dataIn.readUTF(); logger.debug("Snapshot Class Name for {} is {}", storageDirectory, snapshotClass); if (!snapshotClass.equals(HashMapSnapshot.class.getName())) { throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using the " + snapshotClass + " class; cannot restore using " + getClass().getName()); } final int snapshotVersion = dataIn.readInt(); logger.debug("Snapshot version for {} is {}", storageDirectory, snapshotVersion); if (snapshotVersion > getVersion()) { throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using version " + snapshotVersion + " of the " + snapshotClass + " class; cannot restore using Version " + getVersion()); } final String serdeEncoding = dataIn.readUTF(); // ignore serde class name for now logger.debug("Serde encoding for Snapshot at {} is {}", storageDirectory, serdeEncoding); final int serdeVersion = dataIn.readInt(); logger.debug("Serde version for Snapshot at {} is {}", storageDirectory, serdeVersion); final long maxTransactionId = dataIn.readLong(); logger.debug("Max Transaction ID for Snapshot at {} is {}", storageDirectory, maxTransactionId); final int numRecords = dataIn.readInt(); logger.debug("Number of Records for Snapshot at {} is {}", storageDirectory, numRecords); final SerDe<T> serde = serdeFactory.createSerDe(serdeEncoding); serde.readHeader(dataIn); return new SnapshotHeader(serde, serdeVersion, maxTransactionId, numRecords); }
private StartHeader readStartHeader(final long startHeaderCrc) throws IOException { final StartHeader startHeader = new StartHeader(); // using Stream rather than ByteBuffer for the benefit of the // built-in CRC check try (DataInputStream dataInputStream = new DataInputStream(new CRC32VerifyingInputStream( new BoundedSeekableByteChannelInputStream(channel, 20), 20, startHeaderCrc))) { startHeader.nextHeaderOffset = Long.reverseBytes(dataInputStream.readLong()); startHeader.nextHeaderSize = Long.reverseBytes(dataInputStream.readLong()); startHeader.nextHeaderCrc = 0xffffFFFFL & Integer.reverseBytes(dataInputStream.readInt()); return startHeader; } }
@Override public ProgressiveDownloadAction readFromStream(int version, DataInputStream input) throws IOException { Uri uri = Uri.parse(input.readUTF()); boolean isRemoveAction = input.readBoolean(); int dataLength = input.readInt(); byte[] data = new byte[dataLength]; input.readFully(data); String customCacheKey = input.readBoolean() ? input.readUTF() : null; return new ProgressiveDownloadAction(uri, isRemoveAction, data, customCacheKey); } };