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

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

本文整理了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

@Override
public void readURL( final URL url ) {
  try {
    log.info("reading file " + url.toString());
    InputStream inputStream = IOUtils.getInputStream(url);
    parse(inputStream);
  } catch (JAXBException | SAXException e) {
    throw new RuntimeException(e);
  }
}

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

@Override
public void readFile(final String filename) {
  try {
    log.info("reading file " + filename);
    InputStream inputStream = IOUtils.getInputStream(filename);
    parse(inputStream);
  } catch (JAXBException | SAXException e) {
    throw new RuntimeException(e);
  }
}

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

private static XMLStreamReader getStreamReader(final String fileName) {
  final XMLInputFactory xmlif = XMLInputFactory.newInstance();
  try {
    final InputStream stream = IOUtils.getInputStream(fileName);
    return xmlif.createXMLStreamReader( stream );
  }
  catch (Exception e) {
    throw new ParsingException( e );
  }
}

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

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

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

public static BufferedReader getBufferedReader(final URL url, final Charset charset) throws UncheckedIOException {
  BufferedReader infile = null;
  if (url == null) {
    throw new UncheckedIOException(new FileNotFoundException("No url given (url == null)"));
  }
  try {
    infile = new BufferedReader(new InputStreamReader(getInputStream(url), charset));
  } catch (UncheckedIOException e) {
    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.");
    throw new UncheckedIOException(e);
  }
  return infile;
}

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

@Override
public final void readFile( String filename ){
  log.info("starting unmarshalling " + filename);
  try ( InputStream stream = IOUtils.getInputStream(filename )){
    readStream(stream);
  } catch ( IOException e) {
    throw new UncheckedIOException(e);
  }
}

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

/**
 * Tries to open the specified file for reading and returns a BufferedReader 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.
 *
 * @param filename The file to read, may contain the ending ".gz" to force reading a compressed file.
 * @param charset the Charset of the file to read
 * @return BufferedReader for the specified file.
 * @throws UncheckedIOException
 *
 * <br> author mrieser
 */
public static BufferedReader getBufferedReader(final String filename, final Charset charset) throws UncheckedIOException {
  BufferedReader infile = null;
  if (filename == null) {
    throw new UncheckedIOException(new FileNotFoundException("No filename given (filename == null)"));
  }
  try {
    infile = new BufferedReader(new InputStreamReader(getInputStream(filename), charset));
  } catch (UncheckedIOException e) {
    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.");
    throw new UncheckedIOException(e);
  }
  return infile;
}

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

@Test
public void testGetInputStream_UTFwithBOM() throws IOException {
  String filename = utils.getOutputDirectory() + "test.txt";
  FileOutputStream out = new FileOutputStream(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_UTFwithoutBOM() throws IOException {
  String filename = utils.getOutputDirectory() + "test.txt";
  FileOutputStream out = new FileOutputStream(filename);
  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_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();
}

相关文章