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


Java DataOutputStream.flush方法代碼示例

本文整理匯總了Java中java.io.DataOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java DataOutputStream.flush方法的具體用法?Java DataOutputStream.flush怎麽用?Java DataOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.DataOutputStream的用法示例。


在下文中一共展示了DataOutputStream.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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 {
    Validate.notNull(data, "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:BtoBastian,項目名稱:bStats-Metrics,代碼行數:32,代碼來源:Metrics.java

示例2: testWriteObjectAsByteArray

import java.io.DataOutputStream; //導入方法依賴的package包/類
@Test
public void testWriteObjectAsByteArray() throws Exception {
  // make sure recursive calls to WriteObjectAsByteArray work to test bug 38194
  Object v = new WOABA();
  DataOutputStream out = getDataOutput();
  DataSerializer.writeObjectAsByteArray(v, out);
  out.flush();

  DataInput in = getDataInput();
  byte[] b2 = DataSerializer.readByteArray(in);
  // todo should we deserislize the byte[] and make sure it is equal to v?
  ByteArrayInputStream bais = new ByteArrayInputStream(b2);
  DataInputStream dis = new DataInputStream(bais);
  Object v2 = DataSerializer.readObject(dis);
  if (!(v2 instanceof WOABA)) {
    fail("expected instance of WOABA but found " + v2.getClass());
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:19,代碼來源:DataSerializableJUnitTest.java

示例3: testObjectArray

import java.io.DataOutputStream; //導入方法依賴的package包/類
/**
 * Tests data serializing a <code>Object</code> array
 */
@Test
public void testObjectArray() throws Exception {
  Random random = getRandom();
  SerializableImpl[] array = new SerializableImpl[] {new SerializableImpl(random),
      new SerializableImpl(random), new SerializableImpl(random)};

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObjectArray(array, out);
  out.flush();

  DataInput in = getDataInput();
  SerializableImpl[] array2 = (SerializableImpl[]) DataSerializer.readObjectArray(in);

  assertEquals(array.length, array2.length);
  for (int i = 0; i < array.length; i++) {
    assertEquals(array[i], array2[i]);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:DataSerializableJUnitTest.java

示例4: testHashMapObject

import java.io.DataOutputStream; //導入方法依賴的package包/類
/**
 * Tests data serializing an {@link HashMap} using {@link DataSerializer#writeObject}.
 */
@Test
public void testHashMapObject() throws Exception {
  Random random = getRandom();
  HashMap map = new HashMap();
  int size = random.nextInt(50);
  for (int i = 0; i < size; i++) {
    Object key = new Long(random.nextLong());
    Object value = String.valueOf(random.nextLong());
    map.put(key, value);
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObject(map, out);
  out.flush();

  DataInput in = getDataInput();
  HashMap map2 = (HashMap) DataSerializer.readObject(in);
  assertEquals(map, map2);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:DataSerializableJUnitTest.java

示例5: testVectorObject

import java.io.DataOutputStream; //導入方法依賴的package包/類
/**
 * Tests data serializing an {@link Vector} using {@link DataSerializer#writeObject}.
 */
@Test
public void testVectorObject() throws Exception {
  Random random = getRandom();
  Vector list = new Vector();
  int size = random.nextInt(50);
  for (int i = 0; i < size; i++) {
    list.add(new Long(random.nextLong()));
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObject(list, out);
  out.flush();

  DataInput in = getDataInput();
  Vector list2 = (Vector) DataSerializer.readObject(in);
  assertEquals(list, list2);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:21,代碼來源:DataSerializableJUnitTest.java

示例6: 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:BtoBastian,項目名稱:bStats-Metrics,代碼行數:35,代碼來源:Metrics.java

示例7: execShellCommand

import java.io.DataOutputStream; //導入方法依賴的package包/類
private static void execShellCommand(String command) {
    try {
        Log.d(TAG, "execShellCommand, command: " + command);

        Process su = Runtime.getRuntime().exec("su");
        DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

        outputStream.writeBytes(command + "\n");
        outputStream.flush();

        outputStream.writeBytes("exit\n");
        outputStream.flush();

        su.waitFor();
    }catch(IOException | InterruptedException e){
        Log.e(TAG, "execShellCommand, command: " + command + ", error: " + e.getMessage(), e);
    }
}
 
開發者ID:OpilkiInside,項目名稱:bimdroid,代碼行數:19,代碼來源:BmwIBusService.java

示例8: excuteCBASQuery

import java.io.DataOutputStream; //導入方法依賴的package包/類
private String excuteCBASQuery(String query) throws Exception {
    URL url = new URL(getCbasURL());
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Content-Type",
            "application/x-www-form-urlencoded");
    connection.setRequestProperty("ignore-401",
            "true");

    String encodedQuery = URLEncoder.encode(query, "UTF-8");
    String payload = "statement=" + encodedQuery;

    DataOutputStream out = new DataOutputStream(connection.getOutputStream());
    out.writeBytes(payload);
    out.flush();
    out.close();

    int responseCode = connection.getResponseCode();

    BufferedReader in = new BufferedReader(
            new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    return response.toString();
}
 
開發者ID:couchbaselabs,項目名稱:GitTalent,代碼行數:34,代碼來源:AnalyticsController.java

示例9: run

import java.io.DataOutputStream; //導入方法依賴的package包/類
@Override
public void run() {
    try {
            this.s = new Socket(this.ADDRESS, this.PORT);
            DataInputStream in = new DataInputStream(new BufferedInputStream(this.s.getInputStream()));
            DataOutputStream out = new DataOutputStream(new BufferedOutputStream(this.s.getOutputStream()));
            out.write("Dati?".getBytes());
            out.flush();
            byte[] data = new byte[10000];
            in.read(data);
            System.out.println();
            Map<Calendar, Pacchetto> map = DataManager.estraiMappa(data);
        synchronized (this.dm){
            this.dm.setData(map);
        }
    } catch (IOException ex) {
        Logger.getLogger(SocketTCP.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:ilofX,項目名稱:StazioneMetereologica,代碼行數:20,代碼來源:SocketTCP.java

示例10: testTreeSetWithComparator

import java.io.DataOutputStream; //導入方法依賴的package包/類
/**
 * Tests data serializing an {@link TreeSet}
 */
@Test
public void testTreeSetWithComparator() throws Exception {
  Random random = getRandom();
  int size = random.nextInt(50);
  TreeSet set = new TreeSet(new MyComparator(size));
  for (int i = 0; i < size; i++) {
    set.add(new Long(random.nextLong()));
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeTreeSet(new TreeSet(new MyComparator(0)), out);
  DataSerializer.writeTreeSet(set, out);
  out.flush();

  DataInput in = getDataInput();
  TreeSet emptySet = DataSerializer.readTreeSet(in);
  assertEquals(new TreeSet(new MyComparator(0)), emptySet);
  assertEquals(new MyComparator(0), emptySet.comparator());
  TreeSet set2 = DataSerializer.readTreeSet(in);
  assertEquals(set, set2);
  assertEquals(set.comparator(), set2.comparator());
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:DataSerializableJUnitTest.java

示例11: ping

import java.io.DataOutputStream; //導入方法依賴的package包/類
private static void ping(Socket javaSocket, NetJavaSocketImpl gdxSocket, DataOutputStream dataOutputStream, DataInputStream dataInputStream) throws Exception {
  Log.debug(gdxSocket.getRemoteAddress() + " pinged the server");
  List<ClientIdentifier> clients = Cubes.getServer().getAllClients();
  dataOutputStream.writeInt(clients.size());
  for (ClientIdentifier client : clients) {
    dataOutputStream.writeUTF(client.getPlayer().username);
  }
  dataOutputStream.flush();
  gdxSocket.dispose();
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:11,代碼來源:ServerConnectionInitializer.java

示例12: createTestV1Block

import java.io.DataOutputStream; //導入方法依賴的package包/類
public byte[] createTestV1Block(Compression.Algorithm algo)
    throws IOException {
  Compressor compressor = algo.getCompressor();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  OutputStream os = algo.createCompressionStream(baos, compressor, 0);
  DataOutputStream dos = new DataOutputStream(os);
  BlockType.META.write(dos); // Let's make this a meta block.
  writeTestBlockContents(dos);
  dos.flush();
  algo.returnCompressor(compressor);
  return baos.toByteArray();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:13,代碼來源:TestHFileBlock.java

示例13: executeCommandWithoutWait

import java.io.DataOutputStream; //導入方法依賴的package包/類
/**
 * Execute a command with root user.
 *
 * @param command the command to execute
 */
private void executeCommandWithoutWait(String command) {
    Log.d(TAG, "executeCommandWithoutWait");
    try {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes(command + "\n");
        os.writeBytes("exit\n");
        os.flush();
        Log.d(TAG, command);
    } catch (IOException e) {
        Log.e(TAG, "su command has failed due to: " + e.fillInStackTrace());
    }
}
 
開發者ID:MBach,項目名稱:AutoAirplaneMode,代碼行數:19,代碼來源:AutoAirplaneModeService.java

示例14: 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:youngMen1,項目名稱:JAVA-,代碼行數:48,代碼來源:WeiXinKFUtils.java

示例15: a

import java.io.DataOutputStream; //導入方法依賴的package包/類
public void a(OutputStream outputStream, io ioVar) throws IOException {
    if (outputStream != null && ioVar != null) {
        DataOutputStream anonymousClass1 = new DataOutputStream(this, outputStream) {
            final /* synthetic */ a a;

            public void close() {
            }
        };
        anonymousClass1.writeShort(ioVar.c.length);
        anonymousClass1.write(ioVar.c);
        anonymousClass1.writeShort(0);
        anonymousClass1.flush();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:15,代碼來源:io.java


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