當前位置: 首頁>>代碼示例>>Java>>正文


Java BOMInputStream類代碼示例

本文整理匯總了Java中org.apache.commons.io.input.BOMInputStream的典型用法代碼示例。如果您正苦於以下問題:Java BOMInputStream類的具體用法?Java BOMInputStream怎麽用?Java BOMInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BOMInputStream類屬於org.apache.commons.io.input包,在下文中一共展示了BOMInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readLines

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
@Override
public List<String> readLines(URL url) throws IOException {

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	
	try (InputStream in = new BOMInputStream(url.openStream());) {

		int tmp = -1;
		while ((tmp = in.read()) != -1) {
			out.write(tmp);
		}
	}

	String string = out.toString();
	LOGGER.debug(string);
	XMLDiffFormatter xmlFormatter = new XMLDiffFormatter();
	String format = xmlFormatter.format(string);

	return Stream.of(format.split("\n")).collect(Collectors.toList());
}
 
開發者ID:callakrsos,項目名稱:Gargoyle,代碼行數:21,代碼來源:XmlFileReadModel.java

示例2: getBufferedReader

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
private BufferedReader getBufferedReader() throws IOException {
	String extension;
	Charset charset;
	if (FileUtil.isUrl(uri)) {
		extension = FileUtil.getUrlExtension(uri).toLowerCase(PMS.getLocale());
	} else {
		extension = FileUtil.getExtension(uri).toLowerCase(PMS.getLocale());
	}
	if (extension != null && (extension.equals("m3u8") || extension.equals(".cue"))) {
		charset = StandardCharsets.UTF_8;
	} else {
		charset = StandardCharsets.ISO_8859_1;
	}
	if (FileUtil.isUrl(uri)) {
		return new BufferedReader(new InputStreamReader(new BOMInputStream(new URL(uri).openStream()), charset));
	} else {
		File playlistfile = new File(uri);
		if (playlistfile.length() < 10000000) {
			return new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(playlistfile)), charset));
		}
	}
	return null;
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:24,代碼來源:PlaylistFolder.java

示例3: getFileContent

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Get content from {@link java.nio.file.Path} using UTF8
 *
 * @param path
 * @return
 * @throws CommandException
 */
public String getFileContent(Path path) throws CommandException {
    try {
        File file = path.toFile();
        BOMInputStream inputStream = new BOMInputStream(FileUtils.openInputStream(file), false, boms);
        String fileContent;
        if (inputStream.hasBOM()) {
            fileContent = IOUtils.toString(inputStream, inputStream.getBOMCharsetName());
        } else {
            fileContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
        }
        return fileContent;
    } catch (IOException e) {
        throw new CommandException("Cannot get file content for path: " + path.toString(), e);
    }
}
 
開發者ID:box,項目名稱:mojito,代碼行數:23,代碼來源:CommandHelper.java

示例4: test

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
@Test
public void test() throws IOException {
	ApacheCommonsUtils acu = new ApacheCommonsUtils();

	FileInputStream fis = new FileInputStream(new File("src/test/resources/lotl_utf-8-sansbom.xml"));
	FileInputStream fisBom = new FileInputStream(new File("src/test/resources/lotl_utf-8.xml"));

	assertNotEquals(acu.toBase64(acu.toByteArray(fis)), acu.toBase64(acu.toByteArray(fisBom)));

	fis = new FileInputStream(new File("src/test/resources/lotl_utf-8-sansbom.xml"));
	fisBom = new FileInputStream(new File("src/test/resources/lotl_utf-8.xml"));

	BOMInputStream bomIS = new BOMInputStream(fis);
	BOMInputStream bomISSkipped = new BOMInputStream(fisBom);

	assertEquals(acu.toBase64(acu.toByteArray(bomIS)), acu.toBase64(acu.toByteArray(bomISSkipped)));
}
 
開發者ID:esig,項目名稱:dss,代碼行數:18,代碼來源:TestBOM.java

示例5: processText

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Process a text-based Sitemap. Text sitemaps only list URLs but no
 * priorities, last mods, etc.
 *
 * @param sitemapUrl
 *            URL to sitemap file
 * @param stream
 *            content stream
 * @return The site map
 * @throws IOException
 *             if there is an error reading in the site map content
 */
protected SiteMap processText(URL sitemapUrl, InputStream stream) throws IOException {
    LOG.debug("Processing textual Sitemap");

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

    BOMInputStream bomIs = new BOMInputStream(stream);
    @SuppressWarnings("resource")
    BufferedReader reader = new BufferedReader(new InputStreamReader(bomIs, UTF_8));

    String line;
    int i = 1;
    while ((line = reader.readLine()) != null) {
        if (line.length() > 0 && i <= MAX_URLS) {
            addUrlIntoSitemap(line, textSiteMap, null, null, null, i++);
        }
    }
    textSiteMap.setProcessed(true);

    return textSiteMap;
}
 
開發者ID:crawler-commons,項目名稱:crawler-commons,代碼行數:34,代碼來源:SiteMapParser.java

示例6: processGzippedXML

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Decompress the gzipped content and process the resulting XML Sitemap.
 * 
 * @param url
 *            - URL of the gzipped content
 * @param response
 *            - Gzipped content
 * @return the site map
 * @throws UnknownFormatException
 *             if there is an error parsing the gzip
 * @throws IOException
 *             if there is an error reading in the gzip {@link java.net.URL}
 */
protected AbstractSiteMap processGzippedXML(URL url, byte[] response) throws IOException, UnknownFormatException {

    LOG.debug("Processing gzipped XML");

    InputStream is = new ByteArrayInputStream(response);

    // Remove .gz ending
    String xmlUrl = url.toString().replaceFirst("\\.gz$", "");
    LOG.debug("XML url = {}", xmlUrl);

    BOMInputStream decompressed = new BOMInputStream(new GZIPInputStream(is));
    InputSource in = new InputSource(decompressed);
    in.setSystemId(xmlUrl);
    return processXml(url, in);
}
 
開發者ID:crawler-commons,項目名稱:crawler-commons,代碼行數:29,代碼來源:SiteMapParser.java

示例7: InputTextSubFile

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
public InputTextSubFile(SubtitleFileType inputFormat, String fileName,
		InputStream is) throws InputTextSubException, IOException {
	try {
		tto = createFormat(inputFormat).parseFile(fileName,
				new BOMInputStream(is));
	} catch (FatalParsingException ex) {
		throw new InputTextSubException(
				"Parse error returned by subtitle read library", ex);
	}
	captions = new ArrayList<InputSubtitleLine>(tto.captions.size());
	for (Caption caption : tto.captions.values()) {
		InputSubtitleLine line = new InputSubtitleLine();
		line.setContent(caption.content);
		line.setStartTime(new SubtitleFileTimeWrapper(caption.start)
				.getMSeconds());
		line.setEndTime(new SubtitleFileTimeWrapper(caption.end)
				.getMSeconds());
		captions.add(line);
	}
}
 
開發者ID:riccardove,項目名稱:easyjasub,代碼行數:21,代碼來源:InputTextSubFile.java

示例8: openCsvListReader

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Opens a CSV file.
 *
 * If the given file ends with "gz", then the file is decompressed before using a {@link GZIPInputStream}.
 *
 * @param importFile
 *            the csv file
 * @return a list reader
 * @throws IOException
 *             on io exception
 */
@SuppressWarnings("resource")
protected CsvListReader openCsvListReader(final File importFile) throws IOException {
	// Open file
	InputStream fileStream = new FileInputStream(importFile);

	// Check for compressed file
	if (importFile.getName().toLowerCase().endsWith(".gz")) {
		fileStream = new GZIPInputStream(fileStream);
	}

	// Guess the encoding
	final BOMInputStream inputStream = new BOMInputStream(fileStream, false, ByteOrderMark.UTF_8,
			ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
	final String charset;
	if (inputStream.hasBOM()) {
		charset = inputStream.getBOMCharsetName();
		log.info("BOM detected. Using {} as encoding", charset);
	} else {
		charset = getDefaultEncoding().toString();
		log.info("No BOM detected. Assuming {} as encoding", charset);
	}
	final Reader reader = new InputStreamReader(inputStream, charset);
	return new CsvListReader(reader, new CsvPreference.Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE)
			.skipComments(new CommentMatches("(//|/\\*|#|;).*")).build());
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:37,代碼來源:AbstractCsvReader.java

示例9: simpleConvert

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Simple invocation. Load template and data from a file, run process
 * and return memory model containing results or null if there was a problem.
 * Problems/progress reporting live to given reporter
 * @param templateFile the name of the template file to use
 * @param dataFile  the name of the data file to process
 * @param report the message reporter
 * @param debug set to true to enable voluminous debug message
 * @param allowNullRows set to true to allow output even if some rows don't match
 * @throws IOException 
 */
public Model simpleConvert(String templateFile, String dataFile, ProgressMonitorReporter reporter, boolean debug, boolean allowNullRows) throws IOException {
    Template template = TemplateFactory.templateFrom(templateFile, dc);
    
    File dataFileF = new File(dataFile);
    String filename = dataFileF.getName();
    String filebasename = NameUtils.removeExtension(filename);
    put(ConverterProcess.FILE_NAME, filename);
    put(ConverterProcess.FILE_BASE_NAME, filebasename);
    InputStream is = new BOMInputStream( new FileInputStream(dataFileF) );
    
    ConverterProcess process = new ConverterProcess(dc, is);
    process.setDebug(debug);
    process.setTemplate( template );
    process.setMessageReporter( reporter );
    process.setAllowNullRows(allowNullRows);
    boolean ok = process.process();
    
    return ok ?  process.getModel() : null;
}
 
開發者ID:epimorphics,項目名稱:dclib,代碼行數:31,代碼來源:ConverterService.java

示例10: generateAggregateModel

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Generate a single Jena model from several different files, output it to 
 * specified OutputStream
 * @param aggr String[] String array containing all relevant RDF files "name.extension"
 * @param out OutputStream
 * @param type an instance of ScDemoFile class
 * @throws IOException
 */
public static Model generateAggregateModel(String[] aggr, String lang) 
		throws IOException {
	
	Model model = ModelFactory.createDefaultModel();
	Model subModel = ModelFactory.createDefaultModel();
	
	for (int i=0; i<aggr.length; i++) {
		InputStream in = (JsonldJenaUtils.class).getClassLoader().getResourceAsStream(
				aggr[i]);
		BOMInputStream bIn = new BOMInputStream(in, false);
		
		subModel.read(bIn, null, lang);
		model = model.add(subModel);
		
		subModel.removeAll();
		bIn.close();
		in.close();
	}
	
	return model;
	
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:31,代碼來源:JsonldJenaUtils.java

示例11: processGzip

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
/**
 * Decompress the gzipped content and process the resulting XML Sitemap.
 * 
 * @param url - URL of the gzipped content
 * @param response - Gzipped content
 * @throws MalformedURLException
 * @throws IOException
 * @throws UnknownFormatException
 */
private AbstractSiteMap processGzip(URL url, byte[] response) throws MalformedURLException, IOException,
		UnknownFormatException {

	logger.debug("Processing gzip");

	AbstractSiteMap smi;

	InputStream is = new ByteArrayInputStream(response);

	// 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;
}
 
開發者ID:searchisko,項目名稱:elasticsearch-river-remote,代碼行數:31,代碼來源:SiteMapParser.java

示例12: showByteOfMark

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
private String showByteOfMark(InputStream source) throws IOException {
  ByteOrderMark detectedBOM = new BOMInputStream(source).getBOM();
  if (detectedBOM == null) {
    return "";
  }
  String bom = detectedBOM.toString();
  FileType.logger.log(Level.INFO, "BOM: {0}", bom);
  return " w/ " + bom;
}
 
開發者ID:maumss,項目名稱:file-type-plugin,代碼行數:10,代碼來源:FileType.java

示例13: streamFile

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
private static InputStream streamFile(File file) {
  try {
    return new BOMInputStream(new FileInputStream(file),
      ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
  } catch (FileNotFoundException e) {
    throw new IllegalStateException("File not found: " + file.getAbsolutePath(), e);
  }
}
 
開發者ID:instalint-org,項目名稱:instalint,代碼行數:9,代碼來源:FileMetadata.java

示例14: createCsvParser

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
private CSVParser createCsvParser(String inputFileName, String delimiter) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(inputFileName)), Charsets.UTF_8));
    CSVFormat format = CSVFormat.newFormat(delimiter.charAt(0))
            .withSkipHeaderRecord()
            .withIgnoreEmptyLines()
            .withAllowMissingColumnNames()
            .withQuote('"')
            .withHeader();
    return new CSVParser(reader, format);
}
 
開發者ID:kenshoo,項目名稱:file-format-streaming-converter,代碼行數:11,代碼來源:XlsxToCsvConverterTest.java

示例15: SubtitleFile

import org.apache.commons.io.input.BOMInputStream; //導入依賴的package包/類
public SubtitleFile(String fileName, String fileContents, String stylesStr) throws IOException, FatalParsingException {
  LOGGER.debug("Parsing subtitle file {}", fileName);

  TimedTextFileFormat timedTextFormat;
  switch (FilenameUtils.getExtension(fileName)) {
    case "ass":
      timedTextFormat = new FormatASS();
      break;
    case "srt":
      timedTextFormat = new FormatSRT();
      break;
    default:
      LOGGER.error("invalid subtitle file extension file: {}", fileName);
      throw new UnexpectedError();
  }

  // Convert String to InputStream to match subtitleFile API
  byte[] byteData = fileContents.getBytes("UTF-8");
  // Must use BOMInputStream otherwise files with BOM will broke :(((
  // => http://stackoverflow.com/questions/4897876/reading-utf-8-bom-marker
  try (BOMInputStream inputStream = new BOMInputStream(new ByteArrayInputStream(byteData))) {
    timedText = timedTextFormat.parseFile(fileName, inputStream, StandardCharsets.UTF_8);
  }

  if (timedText.warnings.length() > "List of non fatal errors produced during parsing:\n\n".length()) {
    LOGGER.warn("There was some warnings during parsing. See logs.");
    LOGGER.debug("Got warnings: {}", "\n" + timedText.warnings);
  }

  styles = parseStyles(stylesStr);
  timedText.styling = styles;
  timedText.description = JIJIMAKU_SIGNATURE;
  annotationCaptions = new TreeMap<>();

  // Initialization: add jijimaku mark and set style to Default
  addJijimakuMark();
  timedText.captions.values().stream().forEach(c -> c.style = styles.get("Default"));

  captionIter = timedText.captions.entrySet().iterator();
}
 
開發者ID:juliango202,項目名稱:jijimaku,代碼行數:41,代碼來源:SubtitleFile.java


注:本文中的org.apache.commons.io.input.BOMInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。