本文整理汇总了Java中java.io.DataOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java DataOutputStream.write方法的具体用法?Java DataOutputStream.write怎么用?Java DataOutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataOutputStream
的用法示例。
在下文中一共展示了DataOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSamples
import java.io.DataOutputStream; //导入方法依赖的package包/类
public List<ByteBuffer> getSamples() {
List<ByteBuffer> samples = new LinkedList<ByteBuffer>();
long lastEnd = 0;
for (Line sub : subs) {
long silentTime = sub.from - lastEnd;
if (silentTime > 0) {
samples.add(ByteBuffer.wrap(new byte[]{0, 0}));
} else if (silentTime < 0) {
throw new Error("Subtitle display times may not intersect");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeShort(sub.text.getBytes("UTF-8").length);
dos.write(sub.text.getBytes("UTF-8"));
dos.close();
} catch (IOException e) {
throw new Error("VM is broken. Does not support UTF-8");
}
samples.add(ByteBuffer.wrap(baos.toByteArray()));
lastEnd = sub.to;
}
return samples;
}
示例2: generateSeed
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Generates a device- and invocation-specific seed to be mixed into the
* Linux PRNG.
*/
private static byte[] generateSeed() {
try {
ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream();
DataOutputStream seedBufferOut =
new DataOutputStream(seedBuffer);
seedBufferOut.writeLong(System.currentTimeMillis());
seedBufferOut.writeLong(System.nanoTime());
seedBufferOut.writeInt(Process.myPid());
seedBufferOut.writeInt(Process.myUid());
seedBufferOut.write(BUILD_FINGERPRINT_AND_DEVICE_SERIAL);
seedBufferOut.close();
return seedBuffer.toByteArray();
} catch (IOException e) {
throw new SecurityException("Failed to generate seed", e);
}
}
示例3: generateSeed
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Generates a device- and invocation-specific seed to be mixed into the
* Linux PRNG.
*/
private static byte[] generateSeed() {
try {
ByteArrayOutputStream seedBuffer = new ByteArrayOutputStream();
DataOutputStream seedBufferOut =
new DataOutputStream(seedBuffer);
seedBufferOut.writeLong(System.currentTimeMillis());
seedBufferOut.writeLong(System.nanoTime());
seedBufferOut.writeInt(Process.myPid());
seedBufferOut.writeInt(Process.myUid());
seedBufferOut.write(BUILD_FINGERPRINT_AND_DEVICE_SERIAL);
seedBufferOut.close();
return seedBuffer.toByteArray();
} catch (IOException e) {
throw new SecurityException("Failed to generate seed", e);
}
}
示例4: testSkipBytes
import java.io.DataOutputStream; //导入方法依赖的package包/类
public void testSkipBytes() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
/* Write out various test values NORMALLY */
out.write(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); // 10 bytes of junk to skip
initializeData(out);
byte[] data = baos.toByteArray();
DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data));
int bytesSkipped = 0;
while (bytesSkipped < 10) {
bytesSkipped += in.skipBytes(10 - bytesSkipped);
}
/* Read in various values in LITTLE ENDIAN FORMAT */
byte[] b = new byte[2];
in.readFully(b);
assertEquals(-100, b[0]);
assertEquals(100, b[1]);
assertTrue(in.readBoolean());
assertFalse(in.readBoolean());
}
示例5: serialise
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void
serialise(
DataOutputStream os )
throws IOException
{
super.serialise(os);
// os.writeInt( interval );
if ( hashes != null ){
for (int i=0;i<hashes.length;i++){
os.write( hashes[i] );
os.writeInt( complete[i] );
os.writeInt( downloaded[i] );
os.writeInt( incomplete[i] );
}
}
}
示例6: write
import java.io.DataOutputStream; //导入方法依赖的package包/类
static void write(BinaryAttribute attributes, DataOutputStream out,
BinaryConstantPool cpool, Environment env) throws IOException {
// count the number of attributes
int attributeCount = 0;
for (BinaryAttribute att = attributes; att != null; att = att.next)
attributeCount++;
out.writeShort(attributeCount);
// write out each attribute
for (BinaryAttribute att = attributes; att != null; att = att.next) {
Identifier name = att.name;
byte data[] = att.data;
// write the identifier
out.writeShort(cpool.indexString(name.toString(), env));
// write the length
out.writeInt(data.length);
// write the data
out.write(data, 0, data.length);
}
}
示例7: writeString
import java.io.DataOutputStream; //导入方法依赖的package包/类
private void writeString(final DataOutputStream output, final String value) throws IOException {
for (int i = 0; i < value.length(); i++) {
output.write(value.charAt(i));
}
}
示例8: login
import java.io.DataOutputStream; //导入方法依赖的package包/类
private static void login(){
DroidFile file=new DroidFile("."+File.separator+"login.png");
String cookie=QrcodeLogin.getLoginCookie();
byte[] qrdata=QrcodeLogin.getQRCodeImage();
file.createNewFile();
DataOutputStream out=file.getOutputStream();
try {
out.write(qrdata);
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
QrcodeLogin.waitForVerify(cookie,new QrcodeVerifyListener(){
@Override
public void onVerified(String url, HttpHeader headers) {
// TODO Auto-generated method stub
credential=QrcodeLogin.getCredential(url,headers);
credentialFile.createNewFile();
credential.save(credentialFile);
init();
}
@Override
public void onFailed() {
// TODO Auto-generated method stub
System.out.println("登录失败!");
return;
}
});
}
示例9: writeTo
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void writeTo(DataOutputStream output) throws IOException {
try {
lock.readLock().lock();
super.writeTo(output);
output.write(dataBuffer, 0, dataBuffer.length);
} finally {
lock.readLock().unlock();
}
}
示例10: writeFloat
import java.io.DataOutputStream; //导入方法依赖的package包/类
private void writeFloat(float f, DataOutputStream out) throws IOException {
int v = Float.floatToIntBits(f);
out.write((v >>> 0) & 0xFF);
out.write((v >>> 8) & 0xFF);
out.write((v >>> 16) & 0xFF);
out.write((v >>> 24) & 0xFF);
}
示例11: sendData
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Sends the data to the bStats server.
*
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null");
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.write(compressedData);
outputStream.flush();
outputStream.close();
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
示例12: writeInt64
import java.io.DataOutputStream; //导入方法依赖的package包/类
private void writeInt64(long x, DataOutputStream out) {
try {
for(int i = 0; i < 8; i++) {
out.write((int)(x >> (i * 8)));
}
} catch(Exception e) {
FileLog.e("tmessages", "write int64 error");
}
}
示例13: insertKfAccount
import java.io.DataOutputStream; //导入方法依赖的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;
}
示例14: addPlayer
import java.io.DataOutputStream; //导入方法依赖的package包/类
public synchronized void addPlayer(PlayerThread player) {
if (!isFull()) {
// clientID
int openPos = 1;
// search free position
while (players.containsKey(openPos)) openPos++;
try {
DataOutputStream out = new DataOutputStream(player.client.getOutputStream());
InputStream in = player.client.getInputStream();
// mapSize
out.writeInt(size);
System.out.println("DBG:Size");
// clientID
out.writeInt(openPos);
System.out.println("DBG:openPos");
// stateData
byte[] stateData = getStateData();
// amount of bytes that will be send, state
out.writeInt(stateData.length);
System.out.println("DBG:StateLength");
// state of the Section
out.write(stateData);
System.out.println("DBG:State \n"+ Arrays.toString(stateData));
// confirmation
if (in.read() == 1) {
System.out.println("DBG:Confirmed");
this.players.put(openPos, player);
player.setPlayerID(openPos);
executor.scheduleAtFixedRate(player, 0,
values.playerCommunicationPeriod, TimeUnit.MILLISECONDS);
player.startReader();
}
} catch (IOException ignored) {
System.out.println("Battlefield:ERR_PlayerRejected");
}
} else
System.out.println("Battlefield:ERR_FullBattlefield");
}
示例15: writeShort
import java.io.DataOutputStream; //导入方法依赖的package包/类
private void writeShort(final DataOutputStream output, final short value) throws IOException {
output.write(value >> 0);
output.write(value >> 8);
}