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

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

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

IOUtils.getInputStream介绍

[英]Tries to open the specified file for reading and returns an InputStream for it. Supports gzip-compressed files, such files are automatically decompressed. If the file is not found, a gzip-compressed version of the file with the added ending ".gz" will be searched for and used if found.
[中]尝试打开指定的文件进行读取,并为其返回InputStream。支持gzip压缩文件,此类文件会自动解压缩。如果找不到该文件,将搜索并使用添加了结尾“.gz”的gzip压缩版本的文件。

代码示例

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

  1. @Override
  2. public void readURL( final URL url ) {
  3. try {
  4. log.info("reading file " + url.toString());
  5. InputStream inputStream = IOUtils.getInputStream(url);
  6. parse(inputStream);
  7. } catch (JAXBException | SAXException e) {
  8. throw new RuntimeException(e);
  9. }
  10. }

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

  1. @Override
  2. public void readFile(final String filename) {
  3. try {
  4. log.info("reading file " + filename);
  5. InputStream inputStream = IOUtils.getInputStream(filename);
  6. parse(inputStream);
  7. } catch (JAXBException | SAXException e) {
  8. throw new RuntimeException(e);
  9. }
  10. }

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

  1. private static XMLStreamReader getStreamReader(final String fileName) {
  2. final XMLInputFactory xmlif = XMLInputFactory.newInstance();
  3. try {
  4. final InputStream stream = IOUtils.getInputStream(fileName);
  5. return xmlif.createXMLStreamReader( stream );
  6. }
  7. catch (Exception e) {
  8. throw new ParsingException( e );
  9. }
  10. }

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

  1. private XMLSignalGroups readXmlSignalGroups(String filename) {
  2. return readXmlSignalGroups( new InputSource( IOUtils.getInputStream(filename) ) ) ;
  3. }

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

  1. public static BufferedReader getBufferedReader(final URL url, final Charset charset) throws UncheckedIOException {
  2. BufferedReader infile = null;
  3. if (url == null) {
  4. throw new UncheckedIOException(new FileNotFoundException("No url given (url == null)"));
  5. }
  6. try {
  7. infile = new BufferedReader(new InputStreamReader(getInputStream(url), charset));
  8. } catch (UncheckedIOException e) {
  9. log.fatal("encountered IOException. This will most probably be fatal. Note that for relative path names, the root is no longer the Java root, but the directory where the config file resides.");
  10. throw new UncheckedIOException(e);
  11. }
  12. return infile;
  13. }

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

  1. @Override
  2. public final void readFile( String filename ){
  3. log.info("starting unmarshalling " + filename);
  4. try ( InputStream stream = IOUtils.getInputStream(filename )){
  5. readStream(stream);
  6. } catch ( IOException e) {
  7. throw new UncheckedIOException(e);
  8. }
  9. }

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

  1. /**
  2. * Tries to open the specified file for reading and returns a BufferedReader for it.
  3. * Supports gzip-compressed files, such files are automatically decompressed.
  4. * If the file is not found, a gzip-compressed version of the file with the
  5. * added ending ".gz" will be searched for and used if found.
  6. *
  7. * @param filename The file to read, may contain the ending ".gz" to force reading a compressed file.
  8. * @param charset the Charset of the file to read
  9. * @return BufferedReader for the specified file.
  10. * @throws UncheckedIOException
  11. *
  12. * <br> author mrieser
  13. */
  14. public static BufferedReader getBufferedReader(final String filename, final Charset charset) throws UncheckedIOException {
  15. BufferedReader infile = null;
  16. if (filename == null) {
  17. throw new UncheckedIOException(new FileNotFoundException("No filename given (filename == null)"));
  18. }
  19. try {
  20. infile = new BufferedReader(new InputStreamReader(getInputStream(filename), charset));
  21. } catch (UncheckedIOException e) {
  22. log.fatal("encountered IOException. This will most probably be fatal. Note that for relative path names, the root is no longer the Java root, but the directory where the config file resides.");
  23. throw new UncheckedIOException(e);
  24. }
  25. return infile;
  26. }

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

  1. @Test
  2. public void testGetInputStream_UTFwithBOM() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt";
  4. FileOutputStream out = new FileOutputStream(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_UTFwithoutBOM() throws IOException {
  3. String filename = utils.getOutputDirectory() + "test.txt";
  4. FileOutputStream out = new FileOutputStream(filename);
  5. out.write("ABCdef".getBytes());
  6. out.close();
  7. InputStream in = IOUtils.getInputStream(filename);
  8. 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() }));
  9. in.close();
  10. }

代码示例来源: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. }

相关文章