List of usage examples for org.apache.commons.io ByteOrderMark UTF_8
ByteOrderMark UTF_8
To view the source code for org.apache.commons.io ByteOrderMark UTF_8.
Click Source Link
From source file:org.sonar.api.batch.fs.internal.DefaultInputFile.java
@Override public InputStream inputStream() throws IOException { return contents != null ? new ByteArrayInputStream(contents.getBytes(charset())) : new BOMInputStream(Files.newInputStream(path()), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE); }
From source file:org.sonar.batch.report.SourcePublisher.java
@Override public void publish(BatchReportWriter writer) { for (final BatchComponent resource : resourceCache.all()) { if (!resource.isFile()) { continue; }/*from www.j av a2s .com*/ DefaultInputFile inputFile = (DefaultInputFile) resource.inputComponent(); File iofile = writer.getSourceFile(resource.batchId()); int line = 0; try (FileOutputStream output = new FileOutputStream(iofile); BOMInputStream bomIn = new BOMInputStream(new FileInputStream(inputFile.file()), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE); BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, inputFile.charset()))) { String lineStr = reader.readLine(); while (lineStr != null) { IOUtils.write(lineStr, output, StandardCharsets.UTF_8); line++; if (line < inputFile.lines()) { IOUtils.write("\n", output, StandardCharsets.UTF_8); } lineStr = reader.readLine(); } } catch (IOException e) { throw new IllegalStateException("Unable to store file source in the report", e); } } }
From source file:org.sonar.scanner.scan.filesystem.ByteCharsetDetectorTest.java
@Test public void detectBOM() throws URISyntaxException, IOException { byte[] b = ByteOrderMark.UTF_16BE.getBytes(); assertThat(charsets.detectBOM(b)).isEqualTo(ByteOrderMark.UTF_16BE); assertThat(charsets.detectBOM(readFile("UTF-8"))).isEqualTo(ByteOrderMark.UTF_8); assertThat(charsets.detectBOM(readFile("UTF-16BE"))).isEqualTo(ByteOrderMark.UTF_16BE); assertThat(charsets.detectBOM(readFile("UTF-16LE"))).isEqualTo(ByteOrderMark.UTF_16LE); assertThat(charsets.detectBOM(readFile("UTF-32BE"))).isEqualTo(ByteOrderMark.UTF_32BE); assertThat(charsets.detectBOM(readFile("UTF-32LE"))).isEqualTo(ByteOrderMark.UTF_32LE); }
From source file:org.sonarsource.sonarlint.core.container.analysis.filesystem.FileMetadata.java
private static InputStream streamFile(File file) { try {//from ww w . j ava2 s. com 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); } }
From source file:org.w3.i18n.Utils.java
public static ByteOrderMark findByteOrderMark(byte[] bytes) { if (bytes == null) { throw new NullPointerException("bytes: " + bytes); }//from ww w.jav a 2 s. c o m ByteOrderMark byteOrderMark; try { byteOrderMark = new BOMInputStream(new ByteArrayInputStream(bytes), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE) .getBOM(); } catch (IOException ex) { throw new RuntimeException(ex); } return byteOrderMark; }