当前位置: 首页>>代码示例>>Java>>正文


Java DataOutputStream.close方法代码示例

本文整理汇总了Java中java.io.DataOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java DataOutputStream.close方法的具体用法?Java DataOutputStream.close怎么用?Java DataOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.DataOutputStream的用法示例。


在下文中一共展示了DataOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSerialize

import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
 * Assert that MKeyBase can be serialized and de-serialized as expected.
 *
 * @throws IOException
 * @throws ClassNotFoundException
 */
@Test
public void testSerialize() throws IOException, ClassNotFoundException {
  final MKeyBase key = new MKeyBase("abc".getBytes());
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);

  key.toData(dos);

  DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
  final MKeyBase readKey = new MKeyBase();
  readKey.fromData(dis);

  dis.close();
  dos.close();
  bos.close();

  /** assert that two objects are different but are same for equals and compareTo **/
  assertFalse(key == readKey);
  assertEquals(key, readKey);
  assertTrue(key.equals(readKey));
  assertEquals(key.hashCode(), readKey.hashCode());
  assertEquals(0, key.compareTo(key));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:30,代码来源:MKeyBaseTest.java

示例2: addBodyIfExists

import java.io.DataOutputStream; //导入方法依赖的package包/类
private boolean addBodyIfExists(StethoURLConnectionManager connectionManager, HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty("Content-Type", request.getBodyContentType());

        connectionManager.preConnect(connection, formRequestEntity(body));

        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
        return true;
    }
    return false;
}
 
开发者ID:DLKanth,项目名称:Stetho-Volley,代码行数:17,代码来源:StethoVolleyStack.java

示例3: 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!");
	}
	if (Bukkit.isPrimaryThread()) {
		throw new IllegalAccessException("This method must not be called from the main thread!");
	}
	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:RadBuilder,项目名称:EmojiChat,代码行数:37,代码来源:Metrics.java

示例4: storeRMDTMasterKeyState

import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
protected void storeRMDTMasterKeyState(DelegationKey masterKey)
    throws IOException {
  String dbKey = getRMDTMasterKeyNodeKey(masterKey);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing token master key to " + dbKey);
  }
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  DataOutputStream out = new DataOutputStream(os);
  try {
    masterKey.write(out);
  } finally {
    out.close();
  }
  try {
    db.put(bytes(dbKey), os.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:LeveldbRMStateStore.java

示例5: setSessionLock

import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
 * Creates a session lock file for this process
 */
private void setSessionLock()
{
    try
    {
        File file1 = new File(this.worldDirectory, "session.lock");
        DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file1));

        try
        {
            dataoutputstream.writeLong(this.initializationTime);
        }
        finally
        {
            dataoutputstream.close();
        }
    }
    catch (IOException ioexception)
    {
        ioexception.printStackTrace();
        throw new RuntimeException("Failed to check session lock, aborting");
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:26,代码来源:SaveHandler.java

示例6: saveDat

import java.io.DataOutputStream; //导入方法依赖的package包/类
static boolean saveDat(String path, AhoCorasickDoubleArrayTrie<Pinyin[]> trie, Set<Map.Entry<String, Pinyin[]>> entrySet)
{
    try
    {
        DataOutputStream out = new DataOutputStream(IOUtil.newOutputStream(path + Predefine.BIN_EXT));
        out.writeInt(entrySet.size());
        for (Map.Entry<String, Pinyin[]> entry : entrySet)
        {
            Pinyin[] value = entry.getValue();
            out.writeInt(value.length);
            for (Pinyin pinyin : value)
            {
                out.writeInt(pinyin.ordinal());
            }
        }
        trie.save(out);
        out.close();
    }
    catch (Exception e)
    {
        logger.warning("缓存值dat" + path + "失败");
        return false;
    }

    return true;
}
 
开发者ID:priester,项目名称:hanlpStudy,代码行数:27,代码来源:PinyinDictionary.java

示例7: getUTF8Bytes

import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
 * <p>
 * Get UTF8 bytes from a string
 * </p>
 * 
 * @param string
 *            String
 * @return UTF8 byte array, or null if failed to get UTF8 byte array
 */
public static byte[] getUTF8Bytes(String string) {
    if (string == null)
        return new byte[0];

    try {
        return string.getBytes(ENCODING_UTF8);
    } catch (UnsupportedEncodingException e) {
        /*
         * If system doesn't support UTF-8, use another way
         */
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            dos.writeUTF(string);
            byte[] jdata = bos.toByteArray();
            bos.close();
            dos.close();
            byte[] buff = new byte[jdata.length - 2];
            System.arraycopy(jdata, 2, buff, 0, buff.length);
            return buff;
        } catch (IOException ex) {
            return new byte[0];
        }
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:35,代码来源:AppUtils.java

示例8: main

import java.io.DataOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    dos.writeInt(1);
    dos.writeInt(0x7fffffff);
    dos.writeInt(0x8fffffff);
    dos.writeInt(0xffffffff);

    dos.close();

    ByteArrayInputStream bais =
        new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    for (int i=0; i<4; i++) {
        long res = iis.readUnsignedInt();
        if (res <= 0) {
            throw new RuntimeException("Negative number was read: "+
                                       Long.toString(res, 16));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ReadUnsignedIntTest.java

示例9: createFile

import java.io.DataOutputStream; //导入方法依赖的package包/类
private static File createFile( String name, byte[] data ) throws IOException
{
    File jpeg = File.createTempFile( name, "jpg" );

    jpeg.createNewFile();

    DataOutputStream os = new DataOutputStream( new FileOutputStream( jpeg ) );

    os.write( data );
    os.close();

    // This file will be deleted when the JVM
    // will exit.
    jpeg.deleteOnExit();

    return jpeg;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:18,代码来源:LdifReaderTest.java

示例10: 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,代码来源:MetricsLite.java

示例11: writePrepWithUnkownLength

import java.io.DataOutputStream; //导入方法依赖的package包/类
private int writePrepWithUnkownLength(Writer writer, int start, int n)
    throws IOException {
  for (int i = start; i < (start + n); i++) {
    DataOutputStream out = writer.prepareAppendKey(-1);
    String localKey = String.format(localFormatter, i);
    out.write(localKey.getBytes());
    out.close();
    String value = "value" + localKey;
    out = writer.prepareAppendValue(-1);
    out.write(value.getBytes());
    out.close();
  }
  return (start + n);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:15,代码来源:TestTFile.java

示例12: run

import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        String sb = csebase.getServiceUrl() +"/" + ServiceAEName + "/" + container_name;

        URL mUrl = new URL(sb);

        HttpURLConnection conn = (HttpURLConnection) mUrl.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setInstanceFollowRedirects(false);

        conn.setRequestProperty("Accept", "application/xml");
        conn.setRequestProperty("Content-Type", "application/vnd.onem2m-res+xml;ty=4");
        conn.setRequestProperty("locale", "ko");
        conn.setRequestProperty("X-M2M-RI", "12345");
        conn.setRequestProperty("X-M2M-Origin", ae.getAEid() );

        String reqContent = contentinstance.makeXML();
        conn.setRequestProperty("Content-Length", String.valueOf(reqContent.length()));

        DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
        dos.write(reqContent.getBytes());
        dos.flush();
        dos.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

        String resp = "";
        String strLine="";
        while ((strLine = in.readLine()) != null) {
            resp += strLine;
        }
        if (resp != "") {
            receiver.getResponseBody(resp);
        }
        conn.disconnect();

    } catch (Exception exp) {
        LOG.log(Level.SEVERE, exp.getMessage());
    }
}
 
开发者ID:IoTKETI,项目名称:oneM2M-Application-AndroidSample,代码行数:45,代码来源:MainActivity.java

示例13: writeJsonAsBytes

import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
 * Write the json as bytes -then close the file
 * @param dataOutputStream an outout stream that will always be closed
 * @throws IOException on any failure
 */
private void writeJsonAsBytes(T instance,
    DataOutputStream dataOutputStream) throws IOException {
  try {
    byte[] b = toBytes(instance);
    dataOutputStream.write(b);
  } finally {
    dataOutputStream.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:JsonSerDeser.java

示例14: openConnection

import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
 * Opens an {@link HttpURLConnection} with parameters.
 *
 * @param request
 * @param listener
 * @return an open connection
 * @throws IOException
 */
private HttpURLConnection openConnection(WXRequest request, OnHttpListener listener) throws IOException {
  URL url = new URL(request.url);
  HttpURLConnection connection = createConnection(url);
  connection.setConnectTimeout(request.timeoutMs);
  connection.setReadTimeout(request.timeoutMs);
  connection.setUseCaches(false);
  connection.setDoInput(true);

  if (request.paramMap != null) {
    Set<String> keySets = request.paramMap.keySet();
    for (String key : keySets) {
      connection.addRequestProperty(key, request.paramMap.get(key));
    }
  }

  if ("POST".equals(request.method) || "PUT".equals(request.method) || "PATCH".equals(request.method)) {
    connection.setRequestMethod(request.method);
    if (request.body != null) {
      if (listener != null) {
        listener.onHttpUploadProgress(0);
      }
      connection.setDoOutput(true);
      DataOutputStream out = new DataOutputStream(connection.getOutputStream());
      //TODO big stream will cause OOM; Progress callback is meaningless
      out.write(request.body.getBytes());
      out.close();
      if (listener != null) {
        listener.onHttpUploadProgress(100);
      }
    }
  } else if (!TextUtils.isEmpty(request.method)) {
    connection.setRequestMethod(request.method);
  } else {
    connection.setRequestMethod("GET");
  }

  return connection;
}
 
开发者ID:erguotou520,项目名称:weex-uikit,代码行数:47,代码来源:DefaultWXHttpAdapter.java

示例15: write

import java.io.DataOutputStream; //导入方法依赖的package包/类
public static void write(NBTTagCompound p_74795_0_, File p_74795_1_) throws IOException
{
    DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(p_74795_1_));

    try
    {
        write(p_74795_0_, dataoutputstream);
    }
    finally
    {
        dataoutputstream.close();
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:14,代码来源:CompressedStreamTools.java


注:本文中的java.io.DataOutputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。