public FileHandler(String fileOrClasspath, String contentType) throws IOException { try (BufferedReader r = IOUtils.readerFromString(fileOrClasspath, "utf-8")) { this.content = IOUtils.slurpReader(r); } this.contentType = contentType + "; charset=utf-8"; // always encode in utf-8 } @Override
/** * Returns all the text in the given File as a single String. */ public static String slurpGZippedFile(String filename) throws IOException { Reader r = encodedInputStreamReader(new GZIPInputStream(new FileInputStream( filename)), null); return IOUtils.slurpReader(r); }
/** * Returns all the text in the given File as a single String. */ public static String slurpGZippedFile(File file) throws IOException { Reader r = encodedInputStreamReader(new GZIPInputStream(new FileInputStream( file)), null); return IOUtils.slurpReader(r); }
/** * Returns all the text in the given file with the given encoding. * The string may be empty, if the file is empty. */ public static String slurpFile(String filename, String encoding) throws IOException { Reader r = readerFromString(filename, encoding); return IOUtils.slurpReader(r); }
/** * Read the contents of an input stream, decoding it according to the given character encoding. * @param input The input stream to read from * @return The String representation of that input stream */ public static String slurpInputStream(InputStream input, String encoding) throws IOException { return slurpReader(encodedInputStreamReader(input, encoding)); }
@Override public Annotation create(Reader reader) throws IOException { String text = IOUtils.slurpReader(reader); return createFromText(text); } }
public List<String> parse(Reader r) throws IOException { return parse(IOUtils.slurpReader(r)); }
/** * Returns all the text in the given file with the given * encoding. If the file cannot be read (non-existent, etc.), then * the method throws an unchecked RuntimeIOException. If the caller * is willing to tolerate missing files, they should catch that * exception. */ public static String slurpFileNoExceptions(File file) { try { return IOUtils.slurpReader(encodedInputStreamReader(new FileInputStream(file), null)); } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * Read a gazette mapping in TokensRegex format from the given path * The format is: 'case_sensitive_word \t target_ner_class' (additional info is ignored). * * @param mappingFile The mapping file to read from, as a path either on the filesystem or in your classpath. * * @return The mapping from word to NER tag. */ private static Map<String, String> readRegexnerGazette(String mappingFile) { Map<String, String> mapping = new HashMap<>(); try (BufferedReader reader = IOUtils.readerFromString(mappingFile.trim())){ for (String line : IOUtils.slurpReader(reader).split("\n")) { String[] fields = line.split("\t"); String key = fields[0]; String target = fields[1]; mapping.put(key, target); } } catch (IOException e) { log.warn("Could not read Regex mapping: " + mappingFile); } return Collections.unmodifiableMap(mapping); }
/** * Returns all the text in the given File as a single String. * If the file's name ends in .gz, it is assumed to be gzipped and is silently uncompressed. * * @param file The file to read from * @param encoding The character encoding to assume. This may be null, and * the platform default character encoding is used. */ public static String slurpFile(File file, String encoding) throws IOException { return IOUtils.slurpReader(IOUtils.encodedInputStreamReader( inputStreamFromFile(file), encoding)); }
private static Stream<SentimentDatum> unlabelled(String path) throws IOException { return StreamSupport.stream( IOUtils.iterFilesRecursive(new File(path)).spliterator(), true) .flatMap(x -> new Document(IOUtils.slurpReader(IOUtils.readerFromFile(x))) .sentences() .stream() .map(y -> new SentimentDatum(y.text(), SentimentClass.NEUTRAL))); }
/** * Returns an Iterator over the input sources in the underlying Collection. * * @return an Iterator over the input sources in the underlying Collection. */ @Override public Iterator<Reader> iterator() { Collection<Object> newCollection = new ArrayList<>(); for (Object o : c) { if (o instanceof Reader) { String name = o.toString()+".tmp"; File tmpFile; try { tmpFile = File.createTempFile(name,""); } catch (Exception e) { throw new RuntimeIOException(e); } tmpFile.deleteOnExit(); StringUtils.printToFile(tmpFile, IOUtils.slurpReader((Reader) o), false, false, enc); newCollection.add(tmpFile); } else { newCollection.add(o); } } c = newCollection; return new ReaderIterator(); }
String line; if (oneDocument) { line = IOUtils.slurpReader(r); } else { line = r.readLine();
String text = IOUtils.slurpReader(IOUtils.encodedInputStreamReader(httpExchange.getRequestBody(), encoding));
/** * Returns all the text in the given File. */ public static String slurpGZippedFile(String filename) throws IOException { Reader r = new InputStreamReader(new GZIPInputStream(new FileInputStream( filename))); return IOUtils.slurpReader(r); }
/** * Returns all the text in the given File. */ public static String slurpGZippedFile(File file) throws IOException { Reader r = new InputStreamReader(new GZIPInputStream(new FileInputStream( file))); return IOUtils.slurpReader(r); }
/** * Returns all the text in the given File. */ public static String slurpGZippedFile(String filename) throws IOException { Reader r = encodedInputStreamReader(new GZIPInputStream(new FileInputStream( filename)), null); return IOUtils.slurpReader(r); }
/** * Returns all the text in the given File as a single String. */ public static String slurpGZippedFile(String filename) throws IOException { Reader r = encodedInputStreamReader(new GZIPInputStream(new FileInputStream( filename)), null); return IOUtils.slurpReader(r); }
@Override public Annotation create(Reader reader) throws IOException { String text = IOUtils.slurpReader(reader); return createFromText(text); } }
/** * Returns all the text in the given File as a single String. * If the file's name ends in .gz, it is assumed to be gzipped and is silently uncompressed. * * @param file The file to read from * @param encoding The character encoding to assume. This may be null, and * the platform default character encoding is used. */ public static String slurpFile(File file, String encoding) throws IOException { return IOUtils.slurpReader(IOUtils.encodedInputStreamReader( inputStreamFromFile(file), encoding)); }