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(); } }
private void loadCreationMeta(File crcFile) throws IOException { if (crcFile.exists()) { final DataInputStream ds = new DataInputStream(new FileInputStream(crcFile)); _crc = ds.readLong(); _creationTime = ds.readLong(); ds.close(); } }
/** * Deserialization of Hadoop Writable object. * * @param writable Writable object to deserialize to. * @param bytes byte array to deserialize. */ public static void deserialize(Writable writable, byte[] bytes) throws IOException { DataInputStream dataIn = new DataInputStream(new ByteArrayInputStream(bytes)); writable.readFields(dataIn); dataIn.close(); }
DataInputStream classDataStream = new DataInputStream(classFileStream); data = new byte[classDataStream.available()]; classDataStream.readFully(data); f = new ByteArrayInputStream(data); d = new DataInputStream(f); b = readClass(d); d.close(); if (f != null) { f.close();
@Override public void load(InputStream from) { try { DataInputStream dis = from instanceof BufferedInputStream ? new DataInputStream(from) : new DataInputStream(new BufferedInputStream(from)); byte included = dis.readByte(); boolean hasFeatures = (included & BITMASK_FEATURES_PRESENT) != 0; boolean hasLabels = (included & BITMASK_LABELS_PRESENT) != 0; boolean hasLabelsSameAsFeatures = (included & BITMASK_LABELS_SAME_AS_FEATURES) != 0; boolean hasFeaturesMask = (included & BITMASK_FEATURE_MASK_PRESENT) != 0; boolean hasLabelsMask = (included & BITMASK_LABELS_MASK_PRESENT) != 0; features = (hasFeatures ? Nd4j.read(dis) : null); if (hasLabels) { labels = Nd4j.read(dis); } else if (hasLabelsSameAsFeatures) { labels = features; } else { labels = null; } featuresMask = (hasFeaturesMask ? Nd4j.read(dis) : null); labelsMask = (hasLabelsMask ? Nd4j.read(dis) : null); dis.close(); } catch (Exception e) { throw new RuntimeException("Error loading DataSet",e); } }
public static byte[] readFully(FileLister.Entry fe) throws IOException { DataInputStream in = new DataInputStream(fe.getInputStream()); byte[] contents = new byte[(int)fe.getSize()]; in.readFully(contents); in.close(); return contents; }
/** 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); } }
/** * Loads the zone info map. * * @param in the input stream * @return the map */ private static Map<String, Object> loadZoneInfoMap(InputStream in) throws IOException { Map<String, Object> map = new ConcurrentHashMap<String, Object>(); DataInputStream din = new DataInputStream(in); try { readZoneInfoMap(din, map); } finally { try { din.close(); } catch (IOException ex) { } } map.put("UTC", new SoftReference<DateTimeZone>(DateTimeZone.UTC)); return map; }
protected void read(String filename) { try { DataInputStream rf = IOUtils.getDataInputStream(filename); read(rf, filename); int len1 = rf.readInt(); for (int i = 0; i < len1; i++) { int iO = rf.readInt(); CountWrapper tC = new CountWrapper(); tC.read(rf); this.partTakingVerbs.put(iO, tC); } rf.close(); } catch (IOException e) { e.printStackTrace(); } }
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(); } }
/** * Copy one Writable to another. Copies bytes using data streams. * @param bytes Source Writable * @param tgt Target Writable * @return The target Writable. * @throws IOException e */ public static Writable copyWritable(final byte [] bytes, final Writable tgt) throws IOException { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); try { tgt.readFields(dis); } finally { dis.close(); } return tgt; } }
FileInputStream in = new FileInputStream(idxFileName); in.getChannel().position(offsetInIndex); DataInputStream indexIn = new DataInputStream(in); long offset; try { return -1; } finally { indexIn.close();
/** * Constructs a new MqttPublish object. * @param info the message info byte * @param data the variable header and payload bytes * @throws MqttException if an exception occurs creating the publish * @throws IOException if an exception occurs creating the publish */ public MqttPublish(byte info, byte[] data) throws MqttException, IOException { super(MqttWireMessage.MESSAGE_TYPE_PUBLISH); message = new MqttReceivedMessage(); message.setQos((info >> 1) & 0x03); if ((info & 0x01) == 0x01) { message.setRetained(true); } if ((info & 0x08) == 0x08) { ((MqttReceivedMessage) message).setDuplicate(true); } ByteArrayInputStream bais = new ByteArrayInputStream(data); CountingInputStream counter = new CountingInputStream(bais); DataInputStream dis = new DataInputStream(counter); topicName = decodeUTF8(dis); if (message.getQos() > 0) { msgId = dis.readUnsignedShort(); } byte[] payload = new byte[data.length-counter.getCounter()]; dis.readFully(payload); dis.close(); message.setPayload(payload); }
try { in1 = new DataInputStream( new BufferedInputStream( KettleVFS.getInputStream( KettleVFS.getFilename( file1 ), this ) ) ); in2 = new DataInputStream( new BufferedInputStream( KettleVFS.getInputStream( KettleVFS.getFilename( file2 ), this ) ) ); if ( in1 != null ) { try { in1.close(); } catch ( IOException ignored ) { in2.close(); } catch ( IOException ignored ) {
protected byte[] getBytes(int bufferIndex, String uri, Integer bufferLength) throws IOException { byte[] data; if (uri != null) { if (uri.startsWith("data:")) { //base 64 embed data data = DatatypeConverter.parseBase64Binary(uri.substring(uri.indexOf(",") + 1)); } else { //external file let's load it if (!uri.endsWith(".bin")) { throw new AssetLoadException("Cannot load " + uri + ", a .bin extension is required."); } BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri); InputStream input = (InputStream) info.getManager().loadAsset(key); data = new byte[bufferLength]; DataInputStream dataStream = new DataInputStream(input); dataStream.readFully(data); dataStream.close(); } } else { //no URI this should not happen in a gltf file, only in glb files. throw new AssetLoadException("Buffer " + bufferIndex + " has no uri"); } return data; }
private long[][] deserialize(final String bitsetResource) throws IOException { final DataInputStream dos = new DataInputStream( new GZIPInputStream(this.getClass().getResourceAsStream(bitsetResource))); try { final long[][] bitset = new long[dos.readInt()][]; for (int i = 0; i < bitset.length; i++) { final int wordSize = dos.readInt(); // for duplication, to make bitsets wider final int clone = 0; final long words[] = new long[wordSize * (clone + 1)]; for (int j = 0; j < wordSize; j++) { words[j] = dos.readLong(); } // duplicate long[] n times to the right for (int j = 0; j < clone; j++) { System.arraycopy(words, 0, words, (j + 1) * wordSize, wordSize); } bitset[i] = words; } return bitset; } finally { if (dos != null) { dos.close(); } } } }
/** * Loads the zone info map. * * @param in the input stream * @return the map */ private static Map<String, Object> loadZoneInfoMap(InputStream in) throws IOException { Map<String, Object> map = new ConcurrentHashMap<String, Object>(); DataInputStream din = new DataInputStream(in); try { readZoneInfoMap(din, map); } finally { try { din.close(); } catch (IOException ex) { } } map.put("UTC", new SoftReference<DateTimeZone>(DateTimeZone.UTC)); return map; }
PrintWriter pStream = new PrintWriter(new FileWriter(args[3])); int xMagic = xStream.readInt(); if (xMagic != 2051) throw new RuntimeException("Bad format of xStream"); int yMagic = yStream.readInt(); if (yMagic != 2049) throw new RuntimeException("Bad format of yStream"); int xNumImages = xStream.readInt(); int yNumLabels = yStream.readInt(); if (xNumImages != yNumLabels) throw new RuntimeException("x and y sizes don't match"); xStream.close(); yStream.close(); oStream.close();
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(); } }
@Override public LlapTokenIdentifier decodeTokenIdentifier( Token<LlapTokenIdentifier> token) throws IOException { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(token.getIdentifier())); LlapTokenIdentifier id = new LlapTokenIdentifier(); id.readFields(dis); dis.close(); return id; }