List of usage examples for org.apache.commons.io.input ReaderInputStream ReaderInputStream
public ReaderInputStream(Reader reader, String charsetName)
From source file:com.bigdata.rdf.properties.xml.PropertiesXMLParser.java
@Override public Properties parse(final Reader reader) throws IOException { final InputStream in = new ReaderInputStream(reader, getFormat().getCharset()); try {/*from ww w .j a v a 2s . c om*/ final Properties p = new Properties(); p.loadFromXML(in); return p; } finally { in.close(); } }
From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java
public static Resource readFromJsonString(String input, EClass root) throws IOException { StringReader stringReader = new StringReader(input); ReaderInputStream is = new ReaderInputStream(stringReader, Charset.forName("UTF-8")); Map<String, Object> options = new HashMap<String, Object>(); options.put(EMFJs.OPTION_ROOT_ELEMENT, root); ResourceSet resourceSet = new ResourceSetImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("json", new JsonResourceFactory()); Resource resource = resourceSet.createResource(URI.createURI("in.json")); resource.load(is, options);//from www .j ava 2s .c o m return resource; }
From source file:net.sf.vntconverter.VntConverter.java
/** * Dekodiert einen UTF-8-QUOTED-PRINTABLE-String in einen Java-Unicode-String. *//* w ww . java 2s. com*/ public String decode(String in) { try { InputStream input = MimeUtility.decode(new ReaderInputStream(new StringReader(in), "UTF-8"), "quoted-printable"); StringWriter sw = new StringWriter(); OutputStream output = new WriterOutputStream(sw, "UTF-8"); copyAndClose(input, output); return sw.toString(); } catch (Exception e) { throw new RuntimeException("Exception caught in VntConverter.encode(in):", e); } }
From source file:net.sf.vntconverter.VntConverter.java
/** * Enkodiert einen Java-Unicode-String in einen UTF-8-QUOTED-PRINTABLE-String. */// w ww . j av a 2s . co m public String encode(String in) { try { InputStream input = new ReaderInputStream(new StringReader(in), "UTF-8"); StringWriter sw = new StringWriter(); OutputStream output = MimeUtility.encode(new WriterOutputStream(sw), "quoted-printable"); copyAndClose(input, output); return sw.toString().replaceAll("=\\x0D\\x0A", "").replaceAll("\\x0D\\x0A", "=0D=0A"); } catch (Exception e) { throw new RuntimeException("Exception caught in VntConverter.encode(in):", e); } }
From source file:com.codealot.textstore.FileStore.java
@Override public String storeText(final Reader reader) throws IOException { Objects.requireNonNull(reader, "No reader provided"); // make the digester final MessageDigest digester = getDigester(); // make temp file final Path textPath = Paths.get(this.storeRoot, UUID.randomUUID().toString()); // stream to file, building digest final ReaderInputStream readerAsBytes = new ReaderInputStream(reader, StandardCharsets.UTF_8); try {//from w ww . ja v a 2s.c o m final byte[] bytes = new byte[1024]; int readLength = 0; long totalRead = 0L; while ((readLength = readerAsBytes.read(bytes)) > 0) { totalRead += readLength; digester.update(bytes, 0, readLength); final byte[] readBytes = Arrays.copyOf(bytes, readLength); Files.write(textPath, readBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND); } // check that something was read if (totalRead == 0L) { return this.storeText(""); } // make the hash final String hash = byteToHex(digester.digest()); // store the text, if new final Path finalPath = Paths.get(this.storeRoot, hash); if (Files.exists(finalPath)) { // already existed, so delete uuid named one Files.deleteIfExists(textPath); } else { // rename the file Files.move(textPath, finalPath); } return hash; } finally { if (readerAsBytes != null) { readerAsBytes.close(); } } }
From source file:com.evolveum.midpoint.ninja.action.worker.ImportProducerWorker.java
private void processStream(InputStream input) throws IOException { ApplicationContext appContext = context.getApplicationContext(); PrismContext prismContext = appContext.getBean(PrismContext.class); MatchingRuleRegistry matchingRuleRegistry = appContext.getBean(MatchingRuleRegistry.class); EventHandler handler = new EventHandler() { @Override/*www . j a va 2 s . com*/ public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) { return EventResult.cont(); } @Override public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) { try { if (filter != null) { boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry); if (!match) { operation.incrementSkipped(); return EventResult.skipObject("Object doesn't match filter"); } } if (!matchSelectedType(object.getCompileTimeClass())) { operation.incrementSkipped(); return EventResult.skipObject("Type doesn't match"); } queue.put(object); } catch (Exception ex) { throw new NinjaException("Couldn't import object, reason: " + ex.getMessage(), ex); } return stopAfterFound ? EventResult.skipObject() : EventResult.cont(); } @Override public void handleGlobalError(OperationResult currentResult) { operation.finish(); } }; Validator validator = new Validator(prismContext, handler); validator.setValidateSchema(false); OperationResult result = operation.getResult(); Charset charset = context.getCharset(); Reader reader = new InputStreamReader(input, charset); validator.validate(new ReaderInputStream(reader, charset), result, result.getOperation()); }
From source file:com.twentyn.patentScorer.PatentScorer.java
@Override public void processPatentText(File patentFile, Reader patentTextReader, int patentTextLength) throws IOException, ParserConfigurationException, SAXException, TransformerConfigurationException, TransformerException, XPathExpressionException { System.out.println("Patent text length: " + patentTextLength); CharBuffer buff = CharBuffer.allocate(patentTextLength); int read = patentTextReader.read(buff); System.out.println("Read bytes: " + read); patentTextReader.reset();//from ww w .j av a 2 s . co m String fullContent = new String(buff.array()); PatentDocument patentDocument = PatentDocument .patentDocumentFromXMLStream(new ReaderInputStream(patentTextReader, Charset.forName("utf-8"))); if (patentDocument == null) { LOGGER.info("Found non-patent type document, skipping."); return; } double pr = this.patentModel.ProbabilityOf(fullContent); this.outputWriter .write(objectMapper.writeValueAsString(new ClassificationResult(patentDocument.getFileId(), pr))); this.outputWriter.write(LINE_SEPARATOR); System.out.println("Doc " + patentDocument.getFileId() + " has score " + pr); }
From source file:com.jkoolcloud.tnt4j.streams.configure.StreamsConfigLoader.java
/** * Constructs a new TNT4J-Streams Configuration loader, using the specified {@link java.io.Reader} to obtain the * configuration data.//from www .j a v a2 s . c o m * * @param configReader * reader to get configuration data from * @throws SAXException * if there was an error parsing the configuration * @throws ParserConfigurationException * if there is an inconsistency in the configuration * @throws IOException * if there is an error reading the configuration data */ public StreamsConfigLoader(Reader configReader) throws SAXException, ParserConfigurationException, IOException { load(new ReaderInputStream(configReader, Utils.UTF8)); }
From source file:eu.apenet.dpt.standalone.gui.hgcreation.LevelTreeActions.java
private Node createTree(Document doc, TreeModel model, Object node, HashMap<String, String> paramMap) { CLevelTreeObject obj = (CLevelTreeObject) ((DefaultMutableTreeNode) node).getUserObject(); if (obj.isFile()) { File file = obj.getFile(); try {//from www. java2 s . co m File outputFileTmp = new File(Utilities.TEMP_DIR + ".temp_HG.xml"); FileWriter fileWriter = new FileWriter(outputFileTmp); InputStream xslIs = TransformationTool.class.getResourceAsStream("/xsl/fa2hg.xsl"); Source xsltSource = new StreamSource(xslIs); StringWriter stringWriter = new StringWriter(); StringWriter xslMessages = TransformationTool.createTransformation( fileUtil.readFileAsInputStream(file), stringWriter, xsltSource, paramMap); fileWriter.write(stringWriter.toString()); fileWriter.close(); List<String> filesWithoutEadid = new ArrayList<String>(); if (xslMessages != null && xslMessages.toString().contains("NO_EADID_IN_FILE")) { filesWithoutEadid.add(file.getName()); } else { Reader reader = new FileReader(outputFileTmp); ReaderInputStream readerInputStream = new ReaderInputStream(reader, "UTF-8"); Node fileLevel = stringToNode(doc, readerInputStream); return fileLevel; // el.getParentNode().appendChild(fileLevel); } outputFileTmp.delete(); } catch (Exception e) { LOG.error("Could not create HG part for file: " + file.getName(), e); // createErrorOrWarningPanel(e, true, "Could not create HG"); } } else { Element el = doc.createElement("c"); Element did = doc.createElement("did"); if (!obj.getId().equals("")) { Element unitid = doc.createElement("unitid"); unitid.setAttribute("encodinganalog", "3.1.1"); unitid.setTextContent(obj.getId()); did.appendChild(unitid); } Element title = doc.createElement("unittitle"); title.setAttribute("encodinganalog", "3.1.2"); title.setTextContent(obj.getName()); did.appendChild(title); el.appendChild(did); if (!obj.getDescription().equals("")) { Element scopecontent = doc.createElement("scopecontent"); scopecontent.setAttribute("encodinganalog", "summary"); Element pElt = doc.createElement("p"); pElt.setTextContent(obj.getDescription()); scopecontent.appendChild(pElt); el.appendChild(scopecontent); } for (int i = 0; i < model.getChildCount(node); i++) { Object child = model.getChild(node, i); el.appendChild(createTree(doc, model, child, paramMap)); } return el; } return null; }
From source file:com.twentyn.patentSearch.DocumentIndexer.java
@Override public void processPatentText(File patentFile, Reader patentTextReader, int patentTextLength) throws IOException, ParserConfigurationException, SAXException, TransformerConfigurationException, TransformerException, XPathExpressionException { PatentDocument patentDocument = PatentDocument .patentDocumentFromXMLStream(new ReaderInputStream(patentTextReader, Charset.forName("utf-8"))); if (patentDocument == null) { LOGGER.info("Found non-patent type document, skipping."); return;/*from w w w .j a va 2s. c o m*/ } Document doc = patentDocToLuceneDoc(patentFile, patentDocument); LOGGER.debug("Adding document: " + doc.get("id")); this.indexWriter.addDocument(doc); this.indexWriter.commit(); }