本文整理了Java中org.matsim.core.utils.io.IOUtils.getBufferedWriter()
方法的一些代码示例,展示了IOUtils.getBufferedWriter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.getBufferedWriter()
方法的具体详情如下:
包路径:org.matsim.core.utils.io.IOUtils
类名称:IOUtils
方法名:getBufferedWriter
[英]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. The data written will be encoded as UTF-8 (only relevant if you use Umlauts or other characters not used in plain English).
[中]尝试打开指定的文件进行写入,并为其返回BufferedWriter。如果文件名以“.gz”结尾,数据将自动进行gzip压缩。写入的数据将被编码为UTF-8(仅当您使用Umlauts或其他非纯英语字符时才相关)。
代码示例来源: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.
* @return BufferedWriter for the specified file.
* @throws UncheckedIOException
*/
public static BufferedWriter getBufferedWriter(final String filename, final Charset charset) throws UncheckedIOException {
return getBufferedWriter(filename, charset, 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.
* The data written will be encoded as UTF-8 (only relevant if you use Umlauts or
* other characters not used in plain English).
*
* @param filename The filename where to write the data.
* @return BufferedWriter for the specified file.
* @throws UncheckedIOException
*/
public static BufferedWriter getBufferedWriter(final String filename) throws UncheckedIOException {
return getBufferedWriter(filename, Charset.forName("UTF8"));
}
代码示例来源:origin: matsim-org/matsim
public PrintWriter getWriter(boolean append, String fileName, String header) throws IOException {
PrintWriter writer;
if (append) {
writer = new PrintWriter(IOUtils.getAppendingBufferedWriter(outputPath + "/" + fileName));
} else {
writer = new PrintWriter(IOUtils.getBufferedWriter(outputPath + "/" + fileName));
writer.println(header);
}
return writer;
}
}
代码示例来源:origin: matsim-org/matsim
public void writeStats(final String filename) {
try (BufferedWriter legStatsFile = IOUtils.getBufferedWriter(filename)) {
writeStats(legStatsFile);
} catch (IOException e) {
log.error(e);
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void notifyStartup(final StartupEvent event) {
this.writer = IOUtils.getBufferedWriter( outPath );
try {
this.writer.write( "iter\tagentId\tgroup\tstrategy" );
}
catch (IOException e) {
throw new UncheckedIOException( e );
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void notifyStartup(final StartupEvent event) {
this.writer = IOUtils.getBufferedWriter( outPath );
try {
this.writer.write( "iter\tgroupSize\tstrategy" );
}
catch (IOException e) {
throw new UncheckedIOException( e );
}
}
代码示例来源:origin: matsim-org/matsim
public PlansParser(final String outFile) {
writer = IOUtils.getBufferedWriter( outFile );
try {
writer.write( "driverId\tdirectDistance\taccessDistance\tjointDistance\tegressDistance" );
} catch (IOException e) {
throw new UncheckedIOException( e );
}
}
代码示例来源:origin: matsim-org/matsim
public EventWriterXML(final String outfilename) {
this.out = IOUtils.getBufferedWriter(outfilename);
this.writeHeader();
}
代码示例来源:origin: matsim-org/matsim
public void save() {
String fullXml = this.xmlPane.getText();
try (BufferedWriter writer = IOUtils.getBufferedWriter(this.configFile.getAbsolutePath())) {
writer.write(fullXml);
} catch (IOException e) {
e.printStackTrace();
}
this.configChangeListener.configChanged(this.configFile);
this.btnSave.setEnabled(false);
}
代码示例来源:origin: matsim-org/matsim
private final void writeF2LFile(final ActivityFacilities facilities, final String file) {
log.info(" writing f<-->l connections to "+CONFIG_F2L_OUTPUTF2LFile+"="+file);
try (BufferedWriter bw = IOUtils.getBufferedWriter(file)) {
bw.write("fid\tlid\n");
for (ActivityFacility f : facilities.getFacilities().values()) {
bw.write(f.getId().toString()+"\t"+f.getLinkId().toString()+"\n");
}
} catch (IOException e) {
throw new RuntimeException("Error while writing given outputF2LFile='"+file+"'.", e);
}
log.info(" done. (writing f<-->l connections to "+CONFIG_F2L_OUTPUTF2LFile+"="+file+")");
}
代码示例来源:origin: matsim-org/matsim
public void writeAbsoluteTravelTimes(final String file) {
try {
BufferedWriter timesWriter = IOUtils.getBufferedWriter(file);
writeHeader(timesWriter);
writeRows(timesWriter, true);
timesWriter.flush();
timesWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: matsim-org/matsim
public void writeRelativeTravelTimes(final String file) {
try {
BufferedWriter timesWriter = IOUtils.getBufferedWriter(file);
writeHeader(timesWriter);
writeRows(timesWriter, false);
timesWriter.flush();
timesWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: matsim-org/matsim
@Override
public void notifyStartup(StartupEvent event) {
String fileName = controler.getMATSimControler().getControlerIO().getOutputPath()
+ "/slaveScoreStats.txt";
this.out = IOUtils.getBufferedWriter(fileName);
try {
this.out.write("ITERATION\tavg. EXECUTED\tavg. WORST\tavg. AVG\tavg. BEST\n");
this.out.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_gzipped() throws IOException {
String filename = this.utils.getOutputDirectory() + "test.txt.gz";
BufferedWriter writer = IOUtils.getBufferedWriter(filename);
writer.write("12345678901234567890123456789012345678901234567890");
writer.close();
File file = new File(filename);
Assert.assertTrue("compressed file should be less than 50 bytes, but is " + file.length(), file.length() < 50);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_overwrite() throws IOException {
String filename = this.utils.getOutputDirectory() + "test.txt";
BufferedWriter writer = IOUtils.getBufferedWriter(filename);
writer.write("aaa");
writer.close();
BufferedWriter writer2 = IOUtils.getBufferedWriter(filename);
writer2.write("bbb");
writer2.close();
BufferedReader reader = IOUtils.getBufferedReader(filename);
String line = reader.readLine();
Assert.assertEquals("bbb", line);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_lz4() throws IOException {
String filename = this.utils.getOutputDirectory() + "test.txt.lz4";
BufferedWriter writer = IOUtils.getBufferedWriter(filename);
writer.write("12345678901234567890123456789012345678901234567890");
writer.close();
File file = new File(filename);
Assert.assertTrue("compressed file should be equal 62 bytes, but is " + file.length(), file.length() == 62);
}
代码示例来源:origin: matsim-org/matsim
@Override
public void notifyMobsimInitialized(@SuppressWarnings("rawtypes") MobsimInitializedEvent e) {
String file = matsimServices.getControlerIO().getIterationFilename(matsimServices.getIterationNumber(),
outputFile);
writer = new CompactCSVWriter(IOUtils.getBufferedWriter(file + ".xy.gz"));
writer.writeNext("time", "id", "x", "y", calculator.getHeader());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_encodingIsoLatin1() throws IOException {
String filename = this.utils.getOutputDirectory() + "textsample_IsoLatin1.txt";
BufferedWriter writer = IOUtils.getBufferedWriter(filename, Charset.forName("ISO-8859-1"));
writer.write("äöüÉç");
writer.close();
long crc1 = CRCChecksum.getCRCFromFile(this.utils.getClassInputDirectory() + "textsample_IsoLatin1.txt");
long crc2 = CRCChecksum.getCRCFromFile(filename);
Assert.assertEquals("File was not written with encoding IsoLatin1.", crc1, crc2);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_encodingMacRoman() throws IOException {
String filename = this.utils.getOutputDirectory() + "textsample_MacRoman.txt";
BufferedWriter writer = IOUtils.getBufferedWriter(filename, Charset.forName("MacRoman"));
writer.write("äöüÉç");
writer.close();
long crc1 = CRCChecksum.getCRCFromFile(this.utils.getClassInputDirectory() + "textsample_MacRoman.txt");
long crc2 = CRCChecksum.getCRCFromFile(filename);
Assert.assertEquals("File was not written with encoding MacRoman.", crc1, crc2);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testGetBufferedWriter_encodingUTF8() throws IOException {
String filename = this.utils.getOutputDirectory() + "textsample_UTF8.txt";
BufferedWriter writer = IOUtils.getBufferedWriter(filename);
writer.write("äöüÉç");
writer.close();
long crc1 = CRCChecksum.getCRCFromFile(this.utils.getClassInputDirectory() + "textsample_UTF8.txt");
long crc2 = CRCChecksum.getCRCFromFile(filename);
Assert.assertEquals("File was not written with encoding UTF8.", crc1, crc2);
}
内容来源于网络,如有侵权,请联系作者删除!