本文整理了Java中java.io.DataInputStream.close()
方法的一些代码示例,展示了DataInputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.close()
方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:close
暂无
代码示例来源:origin: google/j2objc
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();
}
}
代码示例来源:origin: apache/incubator-pinot
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();
}
}
代码示例来源:origin: apache/ignite
/**
* 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();
}
代码示例来源:origin: Sable/soot
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();
代码示例来源:origin: deeplearning4j/nd4j
@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);
}
}
代码示例来源:origin: kilim/kilim
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;
}
代码示例来源:origin: kilim/kilim
/** 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); }
}
代码示例来源:origin: prestodb/presto
/**
* 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;
}
代码示例来源:origin: stanfordnlp/CoreNLP
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();
}
}
代码示例来源:origin: org.easymock/easymock
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();
}
}
代码示例来源:origin: apache/hbase
/**
* 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;
}
}
代码示例来源:origin: alibaba/Sentinel
FileInputStream in = new FileInputStream(idxFileName);
in.getChannel().position(offsetInIndex);
DataInputStream indexIn = new DataInputStream(in);
long offset;
try {
return -1;
} finally {
indexIn.close();
代码示例来源:origin: eclipse/paho.mqtt.java
/**
* 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);
}
代码示例来源:origin: pentaho/pentaho-kettle
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 ) {
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
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;
}
代码示例来源:origin: RoaringBitmap/RoaringBitmap
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();
}
}
}
}
代码示例来源:origin: joda-time/joda-time
/**
* 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;
}
代码示例来源:origin: stanfordnlp/CoreNLP
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();
代码示例来源:origin: cglib/cglib
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();
}
}
代码示例来源:origin: apache/hive
@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;
}
内容来源于网络,如有侵权,请联系作者删除!