當前位置: 首頁>>代碼示例>>Java>>正文


Java DataOutputStream.write方法代碼示例

本文整理匯總了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;
}
 
開發者ID:begeekmyfriend,項目名稱:mp4parser_android,代碼行數:25,代碼來源:QuicktimeTextTrackImpl.java

示例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);
    }
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:21,代碼來源:PRNGFixes.java

示例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);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:21,代碼來源:PRNGFixes.java

示例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());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:LittleEndianDataInputStreamTest.java

示例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] );
		}
	}
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:23,代碼來源:PRUDPPacketReplyScrape.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:BinaryAttribute.java

示例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));
    }
}
 
開發者ID:timstableford,項目名稱:P-BrainAndroid,代碼行數:6,代碼來源:RecordWavMaster.java

示例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;
		}
		
	});
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:34,代碼來源:Launcher.java

示例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();
  }
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:11,代碼來源:ServerDenseFloatRow.java

示例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);
}
 
開發者ID:taki0112,項目名稱:Word2VecJava,代碼行數:8,代碼來源:Word2Vec.java

示例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 :)
}
 
開發者ID:DirolGaming,項目名稱:SBAC-SafeBungeeAdminChat,代碼行數:35,代碼來源:MetricsLite.java

示例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");
    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:10,代碼來源:SerializedData.java

示例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;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:48,代碼來源:WeiXinKFUtils.java

示例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");
}
 
開發者ID:MEstfeller,項目名稱:Invasion,代碼行數:45,代碼來源:BattlefieldThread.java

示例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);
}
 
開發者ID:timstableford,項目名稱:P-BrainAndroid,代碼行數:5,代碼來源:RecordWavMaster.java


注:本文中的java.io.DataOutputStream.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。