Package org.apache.commons.io.input

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


        log.debug("processing stream data");

        Perl5Util util = new Perl5Util();

        try {
            BOMInputStream bomIn = new BOMInputStream(new ByteArrayInputStream(data), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE);
            if (bomIn.hasBOM()) {
                return new String[] { "text/plain" };
            }
        } catch (IOException e) {
            log.error("TextFileDetector: error detecting byte order mark");
        }
View Full Code Here


     * @return wrapped input stream
     */
    @Nonnull
    public static InputStream wrap(@Nonnull InputStream delegate) {
        checkNotNull(delegate, "delegate cannot be null");
        return new BOMInputStream(delegate, ByteOrderMark.UTF_8,
                ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE,
                ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
    }
View Full Code Here

   * @return
   * @throws UnknownFormatException
   */
  private AbstractSiteMap processXml(URL sitemapUrl, byte[] xmlContent) throws UnknownFormatException {

    BOMInputStream bomIs = new BOMInputStream(new ByteArrayInputStream(xmlContent));
    InputSource is = new InputSource();
    is.setCharacterStream(new BufferedReader(new InputStreamReader(bomIs)));
    return processXml(sitemapUrl, is);
  }
View Full Code Here

    logger.debug("Processing textual Sitemap");

    SiteMap textSiteMap = new SiteMap(sitemapUrl);
    textSiteMap.setType(SitemapType.TEXT);

    BOMInputStream bomIs = new BOMInputStream(new ByteArrayInputStream(content));
    @SuppressWarnings("resource")
    BufferedReader reader = new BufferedReader(new InputStreamReader(bomIs));

    String line;
View Full Code Here

    // 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

    }

    @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

    }

    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

        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

  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

    }

    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

TOP

Related Classes of org.apache.commons.io.input.BOMInputStream

Copyright © 2018 www.massapicom. 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.