org.matsim.core.utils.io.IOUtils.getOutputStream()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中org.matsim.core.utils.io.IOUtils.getOutputStream()方法的一些代码示例,展示了IOUtils.getOutputStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getOutputStream()方法的具体详情如下:
包路径:org.matsim.core.utils.io.IOUtils
类名称:IOUtils
方法名:getOutputStream

IOUtils.getOutputStream介绍

[英]Returns a buffered and optionally gzip-compressed output stream to the specified file. If the given filename ends with ".gz", the written file content will be automatically compressed with the gzip-algorithm.
[中]将缓冲和可选的gzip压缩输出流返回到指定文件。如果给定的文件名以“.gz”结尾,则写入的文件内容将使用gzip算法自动压缩。

代码示例

代码示例来源:origin: matsim-org/matsim

  1. public static OutputStream getOutputStream(final String filename) throws UncheckedIOException {
  2. return getOutputStream(filename, false);
  3. }

代码示例来源:origin: matsim-org/matsim

  1. /**
  2. * Tries to open the specified file for writing and returns a BufferedWriter for it.
  3. * If the filename ends with ".gz", data will be automatically gzip-compressed.
  4. *
  5. * @param filename The filename where to write the data.
  6. * @param charset the encoding to use to write the file.
  7. * @param append <code>true</code> if the file should be opened for appending, instead of overwriting
  8. * @return BufferedWriter for the specified file.
  9. * @throws UncheckedIOException
  10. */
  11. public static BufferedWriter getBufferedWriter(final String filename, final Charset charset, final boolean append) throws UncheckedIOException {
  12. if (filename == null) {
  13. throw new UncheckedIOException(new FileNotFoundException("No filename given (filename == null)"));
  14. }
  15. try {
  16. return new BufferedWriter(new OutputStreamWriter(getOutputStream(filename, append), charset));
  17. } catch (UncheckedIOException e) {
  18. throw new UncheckedIOException(e);
  19. }
  20. }

代码示例来源:origin: matsim-org/matsim

  1. @Test
  2. public void testGetInputStream_UTFwithBOM_Lz4() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt.lz4";
  4. OutputStream out = IOUtils.getOutputStream(filename);
  5. out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
  6. out.write("ABCdef".getBytes());
  7. out.close();
  8. InputStream in = IOUtils.getInputStream(filename);
  9. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  10. in.close();
  11. }

代码示例来源:origin: matsim-org/matsim

  1. @Test
  2. public void testGetInputStream_UTFwithBOM_Compressed() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt.gz";
  4. OutputStream out = IOUtils.getOutputStream(filename);
  5. out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
  6. out.write("ABCdef".getBytes());
  7. out.close();
  8. InputStream in = IOUtils.getInputStream(filename);
  9. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  10. in.close();
  11. }

代码示例来源:origin: matsim-org/matsim

  1. @Test
  2. public void testGetBufferedReader_UTFwithBOM_lz4() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt.lz4";
  4. OutputStream out = IOUtils.getOutputStream(filename);
  5. out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
  6. out.write("ABCdef".getBytes());
  7. out.close();
  8. {
  9. BufferedReader in = IOUtils.getBufferedReader(filename);
  10. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  11. in.close();
  12. }
  13. {
  14. BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_UTF8);
  15. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  16. in.close();
  17. }
  18. {
  19. BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_WINDOWS_ISO88591);
  20. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  21. in.close();
  22. }
  23. }

代码示例来源:origin: matsim-org/matsim

  1. @Test
  2. public void testGetBufferedReader_UTFwithBOM_Compressed() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt.gz";
  4. OutputStream out = IOUtils.getOutputStream(filename);
  5. out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
  6. out.write("ABCdef".getBytes());
  7. out.close();
  8. {
  9. BufferedReader in = IOUtils.getBufferedReader(filename);
  10. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  11. in.close();
  12. }
  13. {
  14. BufferedReader in = IOUtils.getBufferedReader(filename.substring(0, filename.length() - 3)); // without the .gz extension
  15. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  16. in.close();
  17. }
  18. {
  19. BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_UTF8);
  20. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  21. in.close();
  22. }
  23. {
  24. BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_WINDOWS_ISO88591);
  25. Assert.assertEquals("ABCdef", new String(new byte[] { (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read(), (byte) in.read() }));
  26. in.close();
  27. }
  28. }

相关文章