当前位置: 首页>>代码示例>>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;未经允许,请勿转载。