本文整理了Java中java.io.DataInputStream
类的一些代码示例,展示了DataInputStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream
类的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
[英]Wraps an existing InputStream and reads big-endian typed data from it. Typically, this stream has been written by a DataOutputStream. Types that can be read include byte, 16-bit short, 32-bit int, 32-bit float, 64-bit long, 64-bit double, byte strings, and strings encoded in DataInput.
[中]包装现有的InputStream并从中读取big-endian类型的数据。通常,此流由DataOutputStream写入。可以读取的类型包括byte、16位short、32位int、32位float、64位long、64位double、字节字符串和DataInput中编码的字符串。
代码示例来源: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: stackoverflow.com
...
byte[] imgDataBa = new byte[(int)imgFile.length()];
DataInputStream dataIs = new DataInputStream(new FileInputStream(imgFile));
dataIs.readFully(imgDataBa);
...
代码示例来源:origin: alibaba/jstorm
private static String readContent(String filePath) throws IOException {
DataInputStream ds = null;
try {
ds = new DataInputStream(new FileInputStream(filePath));
return ds.readUTF();
} finally {
org.apache.commons.io.IOUtils.closeQuietly(ds);
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public byte[] readBytes() throws IOException {
int length = dis.readInt();
byte[] bytes = new byte[length];
dis.read(bytes, 0, length);
return bytes;
}
}
代码示例来源:origin: jenkinsci/jenkins
public byte[] readByteArray() throws IOException {
int bufSize = din.readInt();
if (bufSize < 0) {
throw new IOException("DataInputStream unexpectedly returned negative integer");
}
byte[] buf = new byte[bufSize];
din.readFully(buf);
return buf;
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue // to skip a field
@Override
public String readUTF() throws IOException {
return new DataInputStream(in).readUTF();
}
代码示例来源:origin: apache/kylin
@Override
public KafkaConfig clone() {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
SERIALIZER.serialize(this, new DataOutputStream(baos));
return SERIALIZER.deserialize(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
} catch (IOException e) {
throw new RuntimeException(e);//in mem, should not happen
}
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* Imports an openfst's symbols file
*
* @param filename
* the symbols' filename
* @return HashMap containing the imported string-to-id mapping
* @throws IOException IO went wrong
* @throws NumberFormatException import failed due to input data format
*/
private static HashMap<String, Integer> importSymbols(String filename)
throws NumberFormatException, IOException {
File symfile = new File(filename);
if (!(symfile.exists() && symfile.isFile())) {
return null;
}
FileInputStream fis = new FileInputStream(filename);
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
HashMap<String, Integer> syms = new HashMap<String, Integer>();
String strLine;
while ((strLine = br.readLine()) != null) {
String[] tokens = strLine.split("\\t");
String sym = tokens[0];
Integer index = Integer.parseInt(tokens[1]);
syms.put(sym, index);
}
br.close();
return syms;
}
代码示例来源:origin: cSploit/android
mVendors = new HashMap<>();
fstream = new FileInputStream(
mContext.getFilesDir().getAbsolutePath() + "/tools/nmap/nmap-mac-prefixes");
in = new DataInputStream(fstream);
reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (!line.startsWith("#") && !line.isEmpty()) {
in.close();
} catch (Exception e) {
errorLogging(e);
} finally {
try {
if (fstream != null) fstream.close();
if (in != null) in.close();
if (reader != null) reader.close();
} catch (IOException e) {
代码示例来源:origin: google/guava
@SuppressWarnings("deprecation") // testing a deprecated method
public void testWriteBytes() throws IOException {
/* Write out various test values in LITTLE ENDIAN FORMAT */
out.writeBytes("r\u00C9sum\u00C9");
byte[] data = baos.toByteArray();
/* Setup input streams */
DataInput in = new DataInputStream(new ByteArrayInputStream(data));
/* Read in various values NORMALLY */
byte[] b = new byte[6];
in.readFully(b);
assertEquals("r\u00C9sum\u00C9".getBytes(Charsets.ISO_8859_1), b);
}
代码示例来源:origin: apache/flink
public static final void testSerialization(String[] values) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
DataOutputStream serializer = new DataOutputStream(baos);
for (String value : values) {
StringValue.writeString(value, serializer);
}
serializer.close();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream deserializer = new DataInputStream(bais);
int num = 0;
while (deserializer.available() > 0) {
String deser = StringValue.readString(deserializer);
assertEquals("DeserializedString differs from original string.", values[num], deser);
num++;
}
assertEquals("Wrong number of deserialized values", values.length, num);
}
代码示例来源:origin: Javen205/IJPay
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
OutputStream out = new DataOutputStream(conn.getOutputStream());
byte[] mediaDatas = mediaData.toString().getBytes();
out.write(mediaDatas);
DataInputStream fs = new DataInputStream(new FileInputStream(file));
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = fs.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
BufferedReader read = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8));
String valueString = null;
StringBuffer bufferRes = null;
bufferRes = new StringBuffer();
while ((valueString = read.readLine()) != null) {
bufferRes.append(valueString);
代码示例来源:origin: apache/hive
@Test
public void testHLLSparseSerialization() throws IOException {
HyperLogLog hll = HyperLogLog.builder().setEncoding(EncodingType.SPARSE).build();
Random rand = new Random(SEED);
for (int i = 0; i < size; i++) {
hll.addLong(rand.nextLong());
}
FileOutputStream fos = new FileOutputStream(testFile);
DataOutputStream out = new DataOutputStream(fos);
HyperLogLogUtils.serializeHLL(out, hll);
FileInputStream fis = new FileInputStream(testFile);
DataInputStream in = new DataInputStream(fis);
HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in);
assertEquals(hll, deserializedHLL);
assertEquals(hll.toString(), deserializedHLL.toString());
assertEquals(hll.toStringExtended(), deserializedHLL.toStringExtended());
assertEquals(hll.hashCode(), deserializedHLL.hashCode());
assertEquals(hll.count(), deserializedHLL.count());
}
代码示例来源:origin: wildfly/wildfly
public Connection(Socket sock) throws IOException {
this.sock=sock;
this.in=new DataInputStream(sock.getInputStream());
this.out=new DataOutputStream(sock.getOutputStream());
}
代码示例来源:origin: stanfordnlp/CoreNLP
log.info("Reading initial LOP weights from file " + flags.initialLopWeights + " ...");
List<double[]> listOfWeights = new ArrayList<>(numLopExpert);
for (String line; (line = br.readLine()) != null; ) {
line = line.trim();
String[] parts = line.split("\t");
} else {
log.info("Reading initial LOP scales from file " + flags.initialLopScales);
try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(
flags.initialLopScales))))) {
initialScales = ConvertByteArray.readDoubleArr(dis);
代码示例来源:origin: alibaba/canal
public void seek(long seekBytes) throws FileNotFoundException, IOException, InterruptedException {
fileInput = new FileInputStream(file);
fileChannel = fileInput.getChannel();
try {
fileChannel.position(seekBytes);
} catch (ClosedByInterruptException e) {
throw new InterruptedException();
}
bufferedInput = new BufferedInputStream(fileInput, size);
dataInput = new DataInputStream(bufferedInput);
offset = seekBytes;
}
代码示例来源:origin: stackoverflow.com
music=new byte[(int) file.length()];//size & length of the file
InputStream is = new FileInputStream (file);
BufferedInputStream bis = new BufferedInputStream (is, 8000);
DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file
int i = 0; // Read the file into the "music" array
while (dis.available() > 0)
{
music[i] = dis.readByte(); // This assignment does not reverse the order
i++;
}
dis.close(); // Close the input stream
代码示例来源:origin: stackoverflow.com
InputStream is = new FileInputStream (file);
BufferedInputStream bis = new BufferedInputStream (is, 8000);
DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file
int i = 0; // Read the file into the "music" array
while (dis.available() > 0)
{
music[i] = dis.readShort(); // This assignment does not reverse the order
i++;
}
dis.close(); // Close the input stream
代码示例来源:origin: hankcs/HanLP
cache.close();
File fixingFile = new File(cacheFile.getAbsolutePath() + ".fixing");
cache = new DataOutputStream(new FileOutputStream(fixingFile));
DataInputStream oldCache = new DataInputStream(new FileInputStream(cacheFile));
while (oldCache.available() >= 4)
int oldId = oldCache.readInt();
if (oldId < 0)
cache.writeInt(oldId);
continue;
cache.writeInt(id);
oldCache.close();
cache.close();
if (!fixingFile.renameTo(cacheFile))
代码示例来源:origin: internetarchive/heritrix3
protected LongIterator beginFpMerge() {
newFpsFile = new File(scratchDir,ArchiveUtils.get17DigitDate()+".fp");
if(newFpsFile.exists()) {
throw new RuntimeException(newFpsFile+" exists");
}
try {
newFps = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFpsFile)));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
newCount = 0;
if(currentFps==null) {
return LongIterators.EMPTY_ITERATOR;
}
try {
oldFps = new DataInputStream(new BufferedInputStream(new FileInputStream(currentFps)));
} catch (FileNotFoundException e1) {
throw new RuntimeException(e1);
}
return new DataFileLongIterator(oldFps);
}
内容来源于网络,如有侵权,请联系作者删除!