use of org.apache.commons.io.input.BOMInputStream in project languagetool by languagetool-org.
the class Main method getInputStreamReader.
private InputStreamReader getInputStreamReader(String filename, String encoding) throws IOException {
String charsetName = encoding != null ? encoding : Charset.defaultCharset().name();
InputStream is = System.in;
if (!isStdIn(filename)) {
is = new FileInputStream(new File(filename));
BOMInputStream bomIn = new BOMInputStream(is, true, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
if (bomIn.hasBOM() && encoding == null) {
charsetName = bomIn.getBOMCharsetName();
}
is = bomIn;
}
return new InputStreamReader(new BufferedInputStream(is), charsetName);
}
use of org.apache.commons.io.input.BOMInputStream in project languagetool by languagetool-org.
the class Main method loadFile.
private void loadFile(File file) {
try (FileInputStream inputStream = new FileInputStream(file)) {
BOMInputStream bomIn = new BOMInputStream(inputStream, false, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE);
String charsetName;
if (bomIn.hasBOM() == false) {
// No BOM found
bom = null;
charsetName = null;
} else {
bom = bomIn.getBOM();
charsetName = bom.getCharsetName();
}
String fileContents = StringTools.readStream(bomIn, charsetName);
textArea.setText(fileContents);
currentFile = file;
updateTitle();
if (recentFiles.contains(file.getAbsolutePath())) {
recentFiles.remove(file.getAbsolutePath());
}
recentFiles.add(file.getAbsolutePath());
localStorage.saveProperty("recentFiles", recentFiles);
updateRecentFilesMenu();
} catch (IOException e) {
Tools.showError(e);
}
}
use of org.apache.commons.io.input.BOMInputStream in project es6draft by anba.
the class ChakraTest method bomReader.
private static BufferedReader bomReader(InputStream is) throws IOException {
BOMInputStream bis = new BOMInputStream(is);
Charset cs = charsetFor(bis, StandardCharsets.UTF_8);
return new BufferedReader(new InputStreamReader(bis, cs));
}
use of org.apache.commons.io.input.BOMInputStream in project es6draft by anba.
the class Resources method readExcludeXML.
/**
* Load the exclusion xml-list for invalid test cases from {@link InputStream}
*/
private static Set<String> readExcludeXML(InputStream is) throws IOException {
Set<String> exclude = new HashSet<>();
Reader reader = new InputStreamReader(new BOMInputStream(is), StandardCharsets.UTF_8);
NodeList ns = xml(reader).getDocumentElement().getElementsByTagName("test");
for (int i = 0, len = ns.getLength(); i < len; ++i) {
exclude.add(((Element) ns.item(i)).getAttribute("id"));
}
return exclude;
}
use of org.apache.commons.io.input.BOMInputStream in project disconf by knightliao.
the class MyStringUtils method multipartFileToString.
public static String multipartFileToString(MultipartFile file) throws IOException {
BOMInputStream bomInputStream = new BOMInputStream(file.getInputStream());
ByteOrderMark bom = bomInputStream.getBOM();
String charsetName = bom == null ? DEFAULT_ENCODING : bom.getCharsetName();
return inputStreamToString(bomInputStream, charsetName);
}
Aggregations