public ImportFileCommand(String id, String model, File file) { super(id, model); this.file = file; this.encoding = EncodingDetector.detect(file); }
protected BufferedReader getLineReader() throws IOException { // Prepare the reader for reading file line by line InputStreamReader isr = EncodingDetector.getInputStreamReader(is, encoding); return new BufferedReader(isr); }
public static String detect(File file) { try { FileInputStream fis = new FileInputStream(file); String encoding = EncodingDetector.detect(fis); logger.debug("Detected encoding for file: " + file.getName() + ": " + encoding); if (encoding == null) { encoding = DEFAULT_ENCODING; } encoding = validateEncoding(encoding); return encoding; } catch(Exception e) { logger.debug("Exception detecting encoding, using default: " + DEFAULT_ENCODING); } return DEFAULT_ENCODING; }
public static String readFileContentsToString(File file, String encoding) throws IOException { return EncodingDetector.getString(file, encoding); }
public static String getString(File file, String encoding) throws IOException { StringWriter sw = new StringWriter(); FileInputStream fis = new FileInputStream(file); logger.debug("Reading file: " + file + " using encoding: " + encoding); encoding = validateEncoding(encoding); IOUtils.copy(fis, sw, encoding); return sw.toString(); } }
private static String validateEncoding(String encoding) { if(!isCharsetSupported(encoding)) { logger.error("Encoding: " + encoding + " not supported. Falling back to UTF-8"); encoding = "UTF-8"; } return encoding; }
public static InputStreamReader getInputStreamReader(InputStream is, String encoding) throws IOException { logger.debug("Reading stream: using encoding: " + encoding); encoding = validateEncoding(encoding); BOMInputStream bis = new BOMInputStream(is); //So that we can remove the BOM return new InputStreamReader(bis, encoding); }
public ImportFileCommand(String id, String model, String revisionId, File file) { super(id, model, revisionId); this.file = file; this.encoding = EncodingDetector.detect(file); }
InputStreamReader s = EncodingDetector.getInputStreamReader(sourceFile, encoding); if (Files.getFileExtension(sourceFile.getName()).equalsIgnoreCase("N3")) ontHandler.getOntModel().read(s, null, "N3");
public static String detect(InputStream is) throws IOException { byte[] buf = new byte[4096]; // (1) UniversalDetector detector = new UniversalDetector(null); // (2) int nread; while ((nread = is.read(buf)) > 0 && !detector.isDone()) { detector.handleData(buf, 0, nread); } // (3) detector.dataEnd(); // (4) String encoding = detector.getDetectedCharset(); if (encoding != null) { logger.debug("Detected encoding = " + encoding); } else { logger.debug("No encoding detected, using default: " + DEFAULT_ENCODING); encoding = DEFAULT_ENCODING; } encoding = validateEncoding(encoding); // (5) detector.reset(); return encoding; }
public ImportJSONLinesFileCommand(String id, String model, String revisedId, File file) { super(id, model, revisedId, file); this.encoding = EncodingDetector.detect(file); }
InputStreamReader s = EncodingDetector.getInputStreamReader(sourceFile, encoding); if (Files.getFileExtension(sourceFile.getName()).equalsIgnoreCase("N3")) ontHandler.getOntModel().read(s, null, "N3");
public ImportJSONFileCommand(String id, String model, String revisedId, File file) { super(id, model, revisedId, file); this.encoding = EncodingDetector.detect(file); }
private Worksheet generateWorksheetFromJSONStream(String sourceName, InputStream is, InputProperties inputTypeParams, Workspace workspace) throws IOException { Worksheet worksheet; String encoding = (String)inputTypeParams.get(InputProperty.ENCODING); int maxNumLines = (inputTypeParams.get(InputProperty.MAX_NUM_LINES) != null)? (int)inputTypeParams.get(InputProperty.MAX_NUM_LINES) : -1; Reader reader = EncodingDetector.getInputStreamReader(is, encoding); Object json = JSONUtil.createJson(reader); JsonImport imp = new JsonImport(json, sourceName, workspace, encoding, maxNumLines); worksheet = imp.generateWorksheet(); return worksheet; } private Worksheet generateWorksheetFromAvroStream(String sourceName, InputStream is, InputProperties inputTypeParams,
private boolean validateFileCommandLineOptions() { inputFile = new File(sourceFilePath); if (!inputFile.exists()) { logger.error("File not found: " + inputFile.getAbsolutePath()); return false; } if(encoding == null) { encoding = EncodingDetector.detect(inputFile); } maxNumLines = -1; if(sMaxNumLines != null) { maxNumLines = Integer.parseInt(sMaxNumLines); } if(sourceName == null) { logger.error("You need to supply a value for '--sourcename'"); return false; } return true; }
logger.info("Loading ontology file: " + ontology.getAbsolutePath()); try { String encoding = EncodingDetector.detect(ontology); mgr.doImport(ontology, encoding); } catch (Exception t) {
String encoding = EncodingDetector.detect(ontology); ontologyManager.doImport(ontology, encoding); } catch (Exception t) {
if (strEncoding == null || strEncoding == "") { try { strEncoding = EncodingDetector.detect(getFile()); } catch (Exception e) { strEncoding = EncodingDetector.DEFAULT_ENCODING;
if(strEncoding == null || strEncoding == "") { try { strEncoding = EncodingDetector.detect(getFile()); } catch(Exception e) { strEncoding = EncodingDetector.DEFAULT_ENCODING;