本文整理汇总了Java中java.io.DataInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream.read方法的具体用法?Java DataInputStream.read怎么用?Java DataInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataInputStream
的用法示例。
在下文中一共展示了DataInputStream.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unGZip
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* GZip解压
*
* @param bContent
* @return
*/
public static byte[] unGZip(byte[] bContent) {
byte[] data = new byte[1024];
try {
ByteArrayInputStream in = new ByteArrayInputStream(bContent);
GZIPInputStream pIn = new GZIPInputStream(in);
DataInputStream objIn = new DataInputStream(pIn);
int len = 0;
int count = 0;
while ((count = objIn.read(data, len, len + 1024)) != -1) {
len = len + count;
}
byte[] trueData = new byte[len];
System.arraycopy(data, 0, trueData, 0, len);
objIn.close();
pIn.close();
in.close();
return trueData;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: loadVarMapping
import java.io.DataInputStream; //导入方法依赖的package包/类
private StringMapping loadVarMapping(ZipFile zf, String varName) throws IOException {
InputStream zis = zf.getInputStream(new ZipEntry(varName + "_Map" + JwatSession.BINext));
//System.out.println("Entry " + varName+"_Map"+JwatSession.BINext);
DataInputStream dis = new DataInputStream(zis);
StringMapping map = new StringMapping();
double val;
String str;
int numEl = dis.read();
for (int i = 0; i < numEl; i++) {
val = dis.readDouble();
str = dis.readUTF();
map.addNewMapping(val, str);
}
return map;
}
示例3: serializeTrieWithTwoLongValues
import java.io.DataInputStream; //导入方法依赖的package包/类
@Test
public void serializeTrieWithTwoLongValues() throws IOException {
byte[] value1 = TrieImplValueTest.makeValue(100);
byte[] value2 = TrieImplValueTest.makeValue(200);
Trie trie = new TrieImpl(new TrieStoreImpl(new HashMapDB()), false)
.put("foo".getBytes(), value1)
.put("bar".getBytes(), value2);
byte[] bytes = trie.serialize();
Assert.assertNotNull(bytes);
ByteArrayInputStream bstream = new ByteArrayInputStream(bytes);
DataInputStream ostream = new DataInputStream(bstream);
Assert.assertEquals(0, ostream.readShort());
byte[] root = new byte[SHA3Helper.DEFAULT_SIZE_BYTES];
ostream.read(root);
Assert.assertArrayEquals(trie.getHash(), root);
}
示例4: getRequiredData
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* Loads an ICU binary data file and returns it as a ByteBuffer.
* The buffer contents is normally read-only, but its position etc. can be modified.
*
* @param itemPath Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
* @return The data as a read-only ByteBuffer.
*/
public static ByteBuffer getRequiredData(String itemPath) {
final Class<ICUBinary> root = ICUBinary.class;
try (InputStream is = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run() {
return root.getResourceAsStream(itemPath);
}
})) {
BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */);
DataInputStream inputStream = new DataInputStream(b);
byte[] bb = new byte[120000];
int n = inputStream.read(bb);
ByteBuffer bytes = ByteBuffer.wrap(bb, 0, n);
return bytes;
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例5: sendHeartBeat
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* Sends a heartbeat to the drone.
*
* @throws IOException if sending the heartbeat to the drone failed
*/
private void sendHeartBeat() throws IOException {
byte[] heartbeatData = ByteUtils.loadMessageFromFile("bin/heartbeat.bin");
int start = 0;
int length = heartbeatData.length;
OutputStream outputStream = socket.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
if (length > 0) {
dataOutputStream.write(heartbeatData, start, length);
}
dataOutputStream.flush();
DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buf = new byte[106];
int bytesRead = dataInputStream.read(buf);
byteArrayOutputStream.write(buf, 0, bytesRead);
}
示例6: insertKfAccount
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* 添加客服帐号
*
* @param keFu
* @return
*/
public static boolean insertKfAccount(KeFu keFu) {
boolean isOk = false;
String token = WeiXinUtils.getToken();
if (token != null) {
String urlString = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + token;
try {
URL url = new URL(urlString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
String kfAccountString = JSONObject.toJSONString(keFu);
httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setDoInput(true);
DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
dataOutputStream.write(kfAccountString.getBytes());
dataOutputStream.flush();
dataOutputStream.close();
DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
StringBuffer stringBuffer = new StringBuffer();
int inputByte = dataInputStream.read();
while (inputByte != -1) {
stringBuffer.append((char) inputByte);
inputByte = dataInputStream.read();
}
String kfString = stringBuffer.toString();
JSONObject jsonObject = JSON.parseObject(kfString);
if (jsonObject.containsKey("errcode")) {
int errcode = jsonObject.getIntValue("errcode");
if (errcode == 0) {
isOk = true;
} else {
//TODO 添加客服账号失败
isOk = false;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return isOk;
}
示例7: BytesEntry
import java.io.DataInputStream; //导入方法依赖的package包/类
public BytesEntry(byte type, DataInputStream in, int length) throws IOException {
super(type);
byte[] b = new byte[length];
int l = in.read(b, 0, length);
while (l < length) {
l += in.read(b, l, length - l);
}
bytes = b;
}
示例8: readNullableString
import java.io.DataInputStream; //导入方法依赖的package包/类
public static String readNullableString(DataInputStream in) throws IOException {
if (in.read() != 0) {
return in.readUTF();
} else {
return null;
}
}
示例9: readFile
import java.io.DataInputStream; //导入方法依赖的package包/类
private void readFile(FileSystem fileSys,Path name) throws IOException {
//Just read file so that getNumBlockLocations are incremented
DataInputStream stm = fileSys.open(name);
byte [] buffer = new byte[4];
stm.read(buffer,0,4);
stm.close();
}
示例10: updateKfAccount
import java.io.DataInputStream; //导入方法依赖的package包/类
/**
* 修改客服帐号
*
* @param keFu
* @return
*/
public static boolean updateKfAccount(KeFu keFu) {
boolean isOk = false;
String token = WeiXinUtils.getToken();
if (token != null) {
String urlString = "https://api.weixin.qq.com/customservice/kfaccount/update?access_token=" + token;
try {
URL url = new URL(urlString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
String kfAccountString = JSONObject.toJSONString(keFu);
httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
httpsURLConnection.setRequestProperty("Content-Type", "application/json");
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setDoInput(true);
DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
dataOutputStream.write(kfAccountString.getBytes());
dataOutputStream.flush();
dataOutputStream.close();
DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
StringBuffer stringBuffer = new StringBuffer();
int inputByte = dataInputStream.read();
while (inputByte != -1) {
stringBuffer.append((char) inputByte);
inputByte = dataInputStream.read();
}
String kfString = stringBuffer.toString();
JSONObject jsonObject = JSON.parseObject(kfString);
if (jsonObject.containsKey("errcode")) {
int errcode = jsonObject.getIntValue("errcode");
if (errcode == 0) {
isOk = true;
} else {
//TODO 添加客服账号失败
isOk = false;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return isOk;
}
示例11: build
import java.io.DataInputStream; //导入方法依赖的package包/类
protected void build(OutputStream os) throws IOException {
DataInputStream dis = new DataInputStream(classLoader.getResourceAsStream(resourceName));
byte[] buf = new byte[256];
int sz;
while( (sz=dis.read(buf))>0 )
os.write(buf,0,sz);
dis.close();
}
示例12: readMessage
import java.io.DataInputStream; //导入方法依赖的package包/类
@Override
protected void readMessage(InputStream in, int msgLength)
throws IOException {
int pos = 0;
DataInputStream dis = new DataInputStream(in);
topic = dis.readUTF();
pos += FormatUtil.toMQttString(topic).length;
if (getQos() != QoS.AT_MOST_ONCE) {
super.readMessage(in, msgLength);
pos += 2;
}
data = new byte[msgLength - pos];
dis.read(data);
}
示例13: someReadingWithMetaBlock
import java.io.DataInputStream; //导入方法依赖的package包/类
private void someReadingWithMetaBlock(Reader reader) throws IOException {
DataInputStream din = null;
readNumMetablocks(reader, 10);
try {
din = reader.getMetaBlock("NO ONE");
assertTrue(false);
}
catch (MetaBlockDoesNotExist me) {
// should catch
}
din = reader.getMetaBlock("TFileMeta100");
int read = din.read();
assertTrue("check for status", (read == -1));
din.close();
}
示例14: loadBinary
import java.io.DataInputStream; //导入方法依赖的package包/类
public static void loadBinary(InputStream inStream) throws IOException {
DataInputStream in = new DataInputStream(inStream);
head = readShortTable(in, HEAD_LENGTH);
int[] tableSizes = new int[INDEX_TABLEEND];
for (int i = 0; i < INDEX_TABLEEND; i++) {
tableSizes[i] = head[i + 1] - head[i];
}
table_scriptIDs = readShortTable(in, tableSizes[INDEX_scriptIDs]);
table_scriptFonts = readShortTable(in, tableSizes[INDEX_scriptFonts]);
table_elcIDs = readShortTable(in, tableSizes[INDEX_elcIDs]);
table_sequences = readShortTable(in, tableSizes[INDEX_sequences]);
table_fontfileNameIDs = readShortTable(in, tableSizes[INDEX_fontfileNameIDs]);
table_componentFontNameIDs = readShortTable(in, tableSizes[INDEX_componentFontNameIDs]);
table_filenames = readShortTable(in, tableSizes[INDEX_filenames]);
table_awtfontpaths = readShortTable(in, tableSizes[INDEX_awtfontpaths]);
table_exclusions = readShortTable(in, tableSizes[INDEX_exclusions]);
table_proportionals = readShortTable(in, tableSizes[INDEX_proportionals]);
table_scriptFontsMotif = readShortTable(in, tableSizes[INDEX_scriptFontsMotif]);
table_alphabeticSuffix = readShortTable(in, tableSizes[INDEX_alphabeticSuffix]);
table_stringIDs = readShortTable(in, tableSizes[INDEX_stringIDs]);
//StringTable cache
stringCache = new String[table_stringIDs.length + 1];
int len = tableSizes[INDEX_stringTable];
byte[] bb = new byte[len * 2];
table_stringTable = new char[len];
in.read(bb);
int i = 0, j = 0;
while (i < len) {
table_stringTable[i++] = (char)(bb[j++] << 8 | (bb[j++] & 0xff));
}
if (verbose) {
dump();
}
}
示例15: readToEndAsArray
import java.io.DataInputStream; //导入方法依赖的package包/类
private static byte[] readToEndAsArray(InputStream input) throws IOException {
DataInputStream dis = new DataInputStream(input);
byte[] stuff = new byte[1024];
ByteArrayOutputStream buff = new ByteArrayOutputStream();
int read;
while ((read = dis.read(stuff)) != -1) {
buff.write(stuff, 0, read);
}
return buff.toByteArray();
}