use of org.apache.commons.io.input.ReaderInputStream in project midpoint by Evolveum.
the class PageImportObject method getInputStream.
private InputStream getInputStream(boolean raw) throws Exception {
if (raw) {
return IOUtils.toInputStream(xmlEditorModel.getObject(), "utf-8");
}
File newFile = null;
try {
// Create new file
MidPointApplication application = getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getImportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
FileUpload uploadedFile = getUploadedFile();
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
return new ReaderInputStream(reader, reader.getEncoding());
} finally {
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
}
use of org.apache.commons.io.input.ReaderInputStream in project xwiki-platform by xwiki.
the class XWikiAttachmentTest method testSetContentWithMaxSize.
@Test
public void testSetContentWithMaxSize() throws Exception {
XWikiAttachment attachment = new XWikiAttachment();
attachment.setContent(new ReaderInputStream(new StringReader("123456789")), 5);
assertEquals("12345", IOUtils.toString(attachment.getContentInputStream(null)));
}
use of org.apache.commons.io.input.ReaderInputStream in project jackrabbit-oak by apache.
the class TikaParserConfigTest method emptyParser.
@Test
public void emptyParser() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<properties>\n" + " <detectors>\n" + " <detector class=\"org.apache.tika.detect.TypeDetector\"/>\n" + " </detectors>\n" + " <parsers>\n" + " <parser class=\"org.apache.tika.parser.DefaultParser\"/>\n" + " <parser class=\"org.apache.tika.parser.EmptyParser\">\n" + " <mime>application/x-archive</mime>\n" + " <mime>application/x-bzip</mime>\n" + " </parser>\n" + " </parsers>\n" + "</properties>";
Set<MediaType> types = TikaParserConfig.getNonIndexedMediaTypes(new ReaderInputStream(new StringReader(xml), "UTF-8"));
assertEquals(2, types.size());
assertTrue(types.contains(MediaType.parse("application/x-archive")));
}
use of org.apache.commons.io.input.ReaderInputStream in project cdap by caskdata.
the class ConfigServiceTest method testConfig.
@Test
public void testConfig() {
String cConfResourceString = "<configuration>\n" + "\n" + " <property>\n" + " <name>stream.zz.threshold</name>\n" + " <value>1</value>\n" + " <description>Some description</description>\n" + " </property>\n" + "\n" + "</configuration>";
ReaderInputStream cConfResource = new ReaderInputStream(new StringReader(cConfResourceString));
CConfiguration cConf = CConfiguration.create(cConfResource);
ConfigEntry cConfEntry = new ConfigEntry("stream.zz.threshold", "1", cConfResource.toString());
// hConf
Configuration hConf = new Configuration();
String hConfResourceString = "<configuration>\n" + "\n" + " <property>\n" + " <name>stream.notification.threshold</name>\n" + " <value>3</value>\n" + " <description>Some description</description>\n" + " </property>\n" + "\n" + "</configuration>";
ReaderInputStream hConfResource = new ReaderInputStream(new StringReader(hConfResourceString));
hConf.addResource(hConfResource);
ConfigEntry hConfEntry = new ConfigEntry("stream.notification.threshold", "3", hConfResource.toString());
// test
ConfigService configService = new ConfigService(cConf, hConf);
List<ConfigEntry> cConfEntries = configService.getCConf();
Assert.assertTrue(cConfEntries.contains(cConfEntry));
List<ConfigEntry> hConfEntries = configService.getHConf();
Assert.assertTrue(hConfEntries.contains(hConfEntry));
}
use of org.apache.commons.io.input.ReaderInputStream in project sw360portal by sw360.
the class CombinedCLIParserTest method testIsApplicableToFailsOnMalformedXML.
@Test
public void testIsApplicableToFailsOnMalformedXML() throws Exception {
AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
when(connector.getAttachmentStream(content, new User(), new Project())).thenReturn(new ReaderInputStream(new StringReader("this is not an xml file")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Aggregations