List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input, String encoding) throws IOException
From source file:com.cognifide.aet.vs.artifacts.ArtifactsDAOMongoDBImpl.java
@Override public String saveArtifact(DBKey dbKey, String data) { return saveArtifact(dbKey, IOUtils.toInputStream(data, StandardCharsets.UTF_8)); }
From source file:cool.pandora.modeller.ui.handlers.iiif.PatchCanvasHandler.java
private static InputStream getCanvasMetadata(final String resourceURI, final String listURI) { final MetadataTemplate metadataTemplate; final List<CanvasScope.Prefix> prefixes = Arrays.asList(new CanvasScope.Prefix(FedoraPrefixes.RDFS), new CanvasScope.Prefix(FedoraPrefixes.MODE), new CanvasScope.Prefix(IIIFPrefixes.SC), new CanvasScope.Prefix(IIIFPrefixes.OA), new CanvasScope.Prefix(IIIFPrefixes.EXIF)); final ResourceIntegerValue resourceHeight = ResourceIntegerValue.init().resourceURI(resourceURI) .resourceProperty(IIIFPredicates.HEIGHT).build(); final int resheight = resourceHeight.render().get(0); final ResourceIntegerValue resourceWidth = ResourceIntegerValue.init().resourceURI(resourceURI) .resourceProperty(IIIFPredicates.WIDTH).build(); final int reswidth = resourceWidth.render().get(0); final String canvasLabel = substringAfter(listURI, "list/"); final CanvasScope scope = new CanvasScope().fedoraPrefixes(prefixes).resourceURI(resourceURI) .listURI(listURI).canvasLabel(canvasLabel).canvasHeight(resheight).canvasWidth(reswidth); metadataTemplate = MetadataTemplate.template().template("template/sparql-update-canvas" + ".mustache") .scope(scope).throwExceptionOnFailure().build(); final String metadata = unescapeXml(metadataTemplate.render()); return IOUtils.toInputStream(metadata, UTF_8); }
From source file:mitm.common.postfix.PostfixMainConfigWriter.java
/** * Sets the new postfix main config by executing the script * /*from w w w.j a v a 2s. co m*/ * @throws PostfixException */ public void writeConfig(String config) throws PostfixException { Check.notNull(config, "config"); List<String> cmd = new LinkedList<String>(); cmd.add(script.getPath()); try { ProcessRunner runner = new ProcessRunner(); runner.setTimeout(TIMEOUT); runner.setInput(IOUtils.toInputStream(config, CharacterEncoding.US_ASCII)); runner.run(cmd); } catch (IOException e) { throw new PostfixException(e); } }
From source file:com.spartasystems.holdmail.domain.Message.java
public MessageContent getContent() { return MimeUtils.parseMessageContent(IOUtils.toInputStream(getRawMessage(), StandardCharsets.UTF_8)); }
From source file:mitm.common.fetchmail.FetchmailConfigWriter.java
private void writeConfig() throws JAXBException, FileNotFoundException, IOException { FetchmailConfig config = FetchmailConfigFactory.unmarshall(System.in); InputStream input = new FileInputStream(sourceFile); try {//w w w . j av a2s . c o m /* * Read the complete input file so we can overwrite it when source and target are equal. */ String content = IOUtils.toString(input, "US-ASCII"); FetchmailConfigBuilder.createConfig(config, IOUtils.toInputStream(content, "US-ASCII"), System.out); } finally { IOUtils.closeQuietly(input); } }
From source file:com.hypirion.io.PipeTest.java
/** * Test that multiple pipes running concurrently won't leave any chars * behind./*from ww w . j av a 2s . c om*/ */ @Test(timeout = 1000) public void testConcurrentStreamPiping() throws Exception { final int charCount = 30; final char[] vals = "123456789".toCharArray(); final int n = vals.length; InputStream[] istreams = new InputStream[n]; // Generate n istreams with charCount equal elements in them. for (int i = 0; i < n; i++) { String s = ""; for (int j = 0; j < charCount; j++) { s += vals[i]; } InputStream is = IOUtils.toInputStream(s, "UTF-8"); istreams[i] = new SlowInputStream(is); } ByteArrayOutputStream wrt = new ByteArrayOutputStream(); Pipe[] pipes = new Pipe[n]; for (int i = 0; i < n; i++) { pipes[i] = new Pipe(istreams[i], wrt); } for (int i = 0; i < n; i++) { pipes[i].start(); } for (int i = 0; i < n; i++) { pipes[i].join(); istreams[i].close(); } // Count up elements and ensure that we've got the correct amount of // characters of each type. String out = wrt.toString("UTF-8"); char[] output = out.toCharArray(); wrt.close(); for (char v : vals) { int sum = 0; for (char c : output) { if (c == v) { sum++; } } assertEquals(charCount, sum); } }
From source file:com.github.opensensingcity.lindt.api.QueryEndpoint.java
@OnMessage public void handleMessage(String message, Session session) throws IOException, InterruptedException { appender.putSession(Thread.currentThread(), session); try {//from www . j a va2s . c om session.getBasicRemote().sendText(gson.toJson(new Response("", "", "", true))); } catch (IOException ex) { java.util.logging.Logger.getLogger(QueryEndpoint.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } if (message.getBytes().length > 10 * Math.pow(2, 10)) { LOG.error("In this web interface request size cannot exceed 10 kB."); appender.removeSession(Thread.currentThread()); return; } Model model = ModelFactory.createDefaultModel(); try { Request request = gson.fromJson(message, Request.class); Query query = QueryFactory.create(request.query); RDFDataMgr.read(model, IOUtils.toInputStream(request.graph, "UTF-8"), base, Lang.TTL); QueryExecution ex = QueryExecutionFactory.create(query, model); Prologue pm = query.getPrologue(); pm.getPrefixMapping().setNsPrefixes(model.getNsPrefixMap()); if (query.isSelectType()) { String result = ResultSetFormatter.asText(ex.execSelect(), pm); session.getBasicRemote().sendText(gson.toJson(new Response("", result, "mappings", false))); } else if (query.isConstructType()) { StringWriter sb = new StringWriter(); Model result = ex.execConstruct(); result.setNsPrefixes(pm.getPrefixMapping()); result.write(sb, "TTL", "http://example.org/"); session.getBasicRemote().sendText(gson.toJson(new Response("", sb.toString(), "graph", false))); } } catch (IllegalArgumentException | IOException | RiotException | QueryParseException | UnsupportedOperationException ex) { LOG.error(ex.getClass().getName() + ": " + ex.getMessage()); return; } appender.removeSession(Thread.currentThread()); }
From source file:com.github.aptd.simulation.elements.graph.TestCNetwork.java
/** * initialize test//from w w w .j av a2s. c o m */ @Before public void ininitialize() { CConfiguration.INSTANCE.loadstring(""); try (final InputStream l_station = new FileInputStream("src/test/resources/asl/station.asl");) { //m_environment = EEnvironment.LOCAL.generate(); m_station = new CStation.CGenerator(l_station, CConfiguration.INSTANCE.agentaction(), //m_environment null); m_track = new CTrack.CGenerator(IOUtils.toInputStream("", "UTF-8"), CConfiguration.INSTANCE.agentaction(), //m_environment null); } catch (final Exception l_exception) { l_exception.printStackTrace(); } }
From source file:com.hortonworks.registries.storage.filestorage.DbFileStorageTest.java
@Test public void testUploadDownload() throws Exception { try {//from w ww .j a va 2s . c o m transactionManager.beginTransaction(TransactionIsolation.SERIALIZABLE); String input = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(FILE_NAME), "UTF-8"); dbFileStorage.upload(IOUtils.toInputStream(input, "UTF-8"), FILE_NAME); InputStream is = dbFileStorage.download(FILE_NAME); String output = IOUtils.toString(is, "UTF-8"); Assert.assertEquals(input, output); transactionManager.commitTransaction(); } catch (Exception e) { transactionManager.rollbackTransaction(); throw e; } }
From source file:com.thruzero.domain.jpa.dao.JpaDataStoreContainer.java
@Override public List<? extends DataStoreEntity> getAllEntities(boolean recursive) { List<DataStoreEntity> result = new ArrayList<DataStoreEntity>(); List<? extends TextEnvelope> textEnvelopes = jpaTextEnvelopeDAO.getTextEnvelopes(containerPath, false); for (TextEnvelope dataEnvelope : textEnvelopes) { try {/* w ww. j a va2s .co m*/ DataStoreEntity data = new SimpleDataStoreEntity( IOUtils.toInputStream(dataEnvelope.getData(), CharEncoding.UTF_8), dataEnvelope.getEntityPath()); result.add(data); } catch (IOException e) { throw new RuntimeException("couldn't convert dataEnvelope to InputStream.", e); } } return result; }