Examples of BOMInputStream


Examples of org.apache.commons.io.input.BOMInputStream

    // Remove .gz ending
    String xmlUrl = url.toString().replaceFirst("\\.gz$", "");

    logger.debug("XML url = " + xmlUrl);

    BOMInputStream decompressed = new BOMInputStream(new GZIPInputStream(is));
    InputSource in = new InputSource(decompressed);
    in.setSystemId(xmlUrl);
    smi = processXml(url, in);
    decompressed.close();
    return smi;
  }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    }

    @Test
    public void testBOMInputStream() throws IOException {
        final URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
        final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
        final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
        try {
            for (final CSVRecord record : parser) {
                final String string = record.get("Date");
                Assert.assertNotNull(string);
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    }

    public static Stylesheet readStylesheet(InputStream stream)
        throws DocumentException, IOException, FB2toPDFException
    {
        BOMInputStream bomStream = new BOMInputStream(stream);
        return readStylesheet(new InputStreamReader(bomStream, "UTF-8"));
    }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

        InputStream strm = getDataStream(problems);
        if (strm == null)
            return "";

        Reader reader = null;
        BOMInputStream bomStream = null;
        StringBuilder str = new StringBuilder();
        try
        {
            bomStream = new BOMInputStream(strm);
            String bomCharsetName = bomStream.getBOMCharsetName();
            if (bomCharsetName == null)
            {
                if (encoding == null || encoding.length() == 0)
                {
                    bomCharsetName = System.getProperty("file.encoding");
                }
                else
                {
                    bomCharsetName = encoding;
                }
            }

            reader = new InputStreamReader(bomStream, bomCharsetName);
            char[] line = new char[2048];
            int count = 0;
            while ((count = reader.read(line, 0, line.length)) >= 0)
            {
                str.append(line, 0, count);
            }
        }
        catch (IOException e)
        {
            problems.add(new EmbedSourceAttributeCouldNotBeReadProblem(source));
        }
        finally
        {
            if (bomStream != null)
            {
                try
                {
                    bomStream.close();
                }
                catch (IOException e)
                {
                }
            }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

  public CoffeeSource(File input) throws IOException {
    this(new FileResource(input));
  }

  private String loadResource(Resource resource, Charset charset) throws IOException {
    BOMInputStream inputStream = new BOMInputStream(resource.getInputStream());
    try {
      if (inputStream.hasBOM()) {
        logger.debug("BOM found %s", inputStream.getBOMCharsetName());
        return IOUtils.toString(inputStream, inputStream.getBOMCharsetName());
      } else {
        logger.debug("Using charset " + charset.name());
        return IOUtils.toString(inputStream, charset.name());
      }
    } finally {
      inputStream.close();
    }
  }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    }

    public static InputStreamReader getInputStreamReader(InputStream is, String encoding) throws IOException {
       
        logger.info("Reading stream: using encoding: " + encoding);
        BOMInputStream bis = new BOMInputStream(is); //So that we can remove the BOM
        return new InputStreamReader(bis, encoding);
    }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    }
    public static InputStreamReader getInputStreamReader(File file, String encoding) throws IOException {
       
        FileInputStream fis = new FileInputStream(file);
        logger.info("Reading file: " + file + " using encoding: " + encoding);
        BOMInputStream bis = new BOMInputStream(fis); //So that we can remove the BOM
        return new InputStreamReader(bis, encoding);
    }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

   */
  private String getResourceContent(final Resource resource)
      throws IOException {
    InputStream is = null;
    try {
      is = new BOMInputStream(uriLocatorFactory.locate(resource.getUri()));
      final String result = IOUtils.toString(is, context.getConfig().getEncoding());
      if (StringUtils.isEmpty(result)) {
        LOG.debug("Empty resource detected: {}", resource.getUri());
      }
      return result;
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    public LessSource(File input) throws IOException {
        this( new FileResource(input) );
    }

    private String loadResource(Resource resource, Charset charset) throws IOException {
        BOMInputStream inputStream = new BOMInputStream( resource.getInputStream() );
        try {
            if( inputStream.hasBOM() ) {
                logger.debug("BOM found %s", inputStream.getBOMCharsetName());
                return IOUtils.toString(inputStream, inputStream.getBOMCharsetName());
            } else {
                logger.debug("Using charset " + charset.name());
                return IOUtils.toString(inputStream, charset.name());
            }
        }
        finally {
            inputStream.close();
        }
    }
View Full Code Here

Examples of org.apache.commons.io.input.BOMInputStream

    List<AfcFile> afcFiles = new ArrayList<AfcFile>();
    List<String> files = new ArrayList<String>();
    Collections.addAll(files, file.list(new SuffixFileFilter(".afc")));
    Collections.sort(files);
    for (String fileName : files) {
      InputStreamReader reader = new InputStreamReader(new BOMInputStream(new FileInputStream(new File(file,
          fileName))), "UTF-8");
      afcFiles.add(new AfcFile(reader, fileName));
    }
    return afcFiles;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.