本文整理了Java中org.matsim.core.utils.io.IOUtils.getOutputStream()
方法的一些代码示例,展示了IOUtils.getOutputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getOutputStream()
方法的具体详情如下:
包路径:org.matsim.core.utils.io.IOUtils
类名称: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
public static OutputStream getOutputStream(final String filename) throws UncheckedIOException {
return getOutputStream(filename, false);
}
代码示例来源:origin: matsim-org/matsim
/**
* Tries to open the specified file for writing and returns a BufferedWriter for it.
* If the filename ends with ".gz", data will be automatically gzip-compressed.
*
* @param filename The filename where to write the data.
* @param charset the encoding to use to write the file.
* @param append <code>true</code> if the file should be opened for appending, instead of overwriting
* @return BufferedWriter for the specified file.
* @throws UncheckedIOException
*/
public static BufferedWriter getBufferedWriter(final String filename, final Charset charset, final boolean append) throws UncheckedIOException {
if (filename == null) {
throw new UncheckedIOException(new FileNotFoundException("No filename given (filename == null)"));
}
try {
return new BufferedWriter(new OutputStreamWriter(getOutputStream(filename, append), charset));
} catch (UncheckedIOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetInputStream_UTFwithBOM_Lz4() throws IOException {
String filename = utils.getOutputDirectory() + "test.txt.lz4";
OutputStream out = IOUtils.getOutputStream(filename);
out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
out.write("ABCdef".getBytes());
out.close();
InputStream in = IOUtils.getInputStream(filename);
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() }));
in.close();
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetInputStream_UTFwithBOM_Compressed() throws IOException {
String filename = utils.getOutputDirectory() + "test.txt.gz";
OutputStream out = IOUtils.getOutputStream(filename);
out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
out.write("ABCdef".getBytes());
out.close();
InputStream in = IOUtils.getInputStream(filename);
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() }));
in.close();
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedReader_UTFwithBOM_lz4() throws IOException {
String filename = utils.getOutputDirectory() + "test.txt.lz4";
OutputStream out = IOUtils.getOutputStream(filename);
out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
out.write("ABCdef".getBytes());
out.close();
{
BufferedReader in = IOUtils.getBufferedReader(filename);
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() }));
in.close();
}
{
BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_UTF8);
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() }));
in.close();
}
{
BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_WINDOWS_ISO88591);
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() }));
in.close();
}
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedReader_UTFwithBOM_Compressed() throws IOException {
String filename = utils.getOutputDirectory() + "test.txt.gz";
OutputStream out = IOUtils.getOutputStream(filename);
out.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
out.write("ABCdef".getBytes());
out.close();
{
BufferedReader in = IOUtils.getBufferedReader(filename);
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() }));
in.close();
}
{
BufferedReader in = IOUtils.getBufferedReader(filename.substring(0, filename.length() - 3)); // without the .gz extension
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() }));
in.close();
}
{
BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_UTF8);
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() }));
in.close();
}
{
BufferedReader in = IOUtils.getBufferedReader(filename, IOUtils.CHARSET_WINDOWS_ISO88591);
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() }));
in.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!