Search in sources :

Example 1 with ReaderInputStream

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);
        }
    }
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStreamReader(java.io.InputStreamReader) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) FileInputStream(java.io.FileInputStream)

Example 2 with ReaderInputStream

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)));
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with ReaderInputStream

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")));
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) StringReader(java.io.StringReader) MediaType(org.apache.tika.mime.MediaType) Test(org.junit.Test)

Example 4 with ReaderInputStream

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));
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ConfigEntry(co.cask.cdap.proto.ConfigEntry) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StringReader(java.io.StringReader) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 5 with ReaderInputStream

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()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Aggregations

ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)25 StringReader (java.io.StringReader)16 Test (org.junit.Test)15 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)8 User (org.eclipse.sw360.datahandler.thrift.users.User)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 HttpEntity (org.apache.http.HttpEntity)3 StatusLine (org.apache.http.StatusLine)3 HttpGet (org.apache.http.client.methods.HttpGet)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)3 TestHelper.assertLicenseInfoParsingResult (org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult)3 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)2