List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testDocPictureNoOle() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).type(APPLICATION_MSWORD) .accept("application/zip").put(ClassLoader.getSystemResourceAsStream("2pic.doc")); Map<String, String> data = readZipArchive((InputStream) response.getEntity()); assertEquals(JPG2_MD5, data.get(JPG2_NAME)); }
From source file:org.apache.hadoop.gateway.topology.file.FileTopologyProviderTest.java
private FileObject createFile(FileObject parent, String name, String resource, long timestamp) throws IOException { FileObject file = parent.resolveFile(name); if (!file.exists()) { file.createFile();// w w w.ja v a 2 s. c om } InputStream input = ClassLoader.getSystemResourceAsStream(resource); OutputStream output = file.getContent().getOutputStream(); IOUtils.copy(input, output); output.flush(); input.close(); output.close(); file.getContent().setLastModifiedTime(timestamp); assertTrue("Failed to create test file " + file.getName().getFriendlyURI(), file.exists()); assertTrue("Failed to populate test file " + file.getName().getFriendlyURI(), file.getContent().getSize() > 0); // ByteArrayOutputStream buffer = new ByteArrayOutputStream(); // IOUtils.copy( file.getContent().getInputStream(), buffer ); // System.out.println( new String( buffer.toString( "UTF-8" ) ) ); return file; }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void pdfTest() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/PDF.pdf"); assertThat(inputStream).isNotNull(); assertThat(textExtractor.extractContent(inputStream, "application/pdf").getTextualContent()) .contains("This is an awesome document on libroffice writter !\n\n\n"); }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java
@Test public void testTemplateWithTags() throws IOException, PrivateEc2ParserException { InputStream templateStream = ClassLoader.getSystemResourceAsStream("./cfn_templates/tags.template"); PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream); assertNotNull(template);//w w w . ja v a 2s . com assertNotNull(template.getEC2Instance().getProperties().getTags()); assertFalse(template.getEC2Instance().getProperties().getTags().isEmpty()); }
From source file:me.crime.loader.DataBaseLoader.java
public void loadURCTable() throws SQLException, ClassNotFoundException { URCCatagoriesDAO dao = URCCatagoriesDAO.class .cast(DaoBeanFactory.create().getDaoBean(URCCatagoriesDAO.class)); // Read in the URC Codes. InputStream s = ClassLoader.getSystemResourceAsStream("me/crime/loader/CrimeData.txt"); if (s == null) { log_.error("unable to find me/crime/loader/CrimeData.txt"); } else {/*from w ww .j ava 2 s .c o m*/ try { BufferedReader bf = new BufferedReader(new InputStreamReader(s)); while (bf.ready()) { String word = bf.readLine().trim().toUpperCase(); if (!word.startsWith("#")) { if (word.length() > 0) { String[] info = word.split(","); URCCatagories urc = dao.findURCbyCatagory(info[0]); if (urc == null) { urc = new URCCatagories(); int rank = Integer.parseInt(info[1].trim()); if (rank == 1) { urc.setCatagorie(info[0].trim()); urc.setCrimeGroup(info[3].trim()); dao.save(urc); } } } } } bf.close(); } catch (IOException e) { log_.error(e.getLocalizedMessage(), e); } } }
From source file:com.jaredjstewart.SampleSecurityManager.java
boolean initializeFromJsonResource(final String jsonResource) { try {//from w w w.java 2s. c om InputStream input = ClassLoader.getSystemResourceAsStream(jsonResource); if (input != null) { initializeFromJson(readJsonFromInputStream(input)); return true; } } catch (IOException ex) { } return false; }
From source file:org.apache.james.mailets.configuration.SmtpConfiguration.java
private StringReader getPatternReader() throws IOException { InputStream patternStream = ClassLoader.getSystemResourceAsStream("smtpserver.xml"); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(patternStream, byteArrayOutputStream); String pattern = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); return new StringReader(pattern); }
From source file:org.apache.geode.examples.security.ExampleSecurityManager.java
public boolean initializeFromJsonResource(final String jsonResource) { try {// ww w .java2 s .c om InputStream input = ClassLoader.getSystemResourceAsStream(jsonResource); if (input != null) { initializeFromJson(readJsonFromInputStream(input)); return true; } } catch (IOException ex) { } return false; }
From source file:org.wte4j.impl.word.PlainTextContentTest.java
private static <E extends SdtElement> E createPlainTextContentControl(Class<E> type) throws JAXBException, IOException { InputStream in = ClassLoader.getSystemResourceAsStream("org/wte4j/impl/word/PlainTextContentControl.xml"); try {/* ww w.j a v a 2 s. c o m*/ String xml = IOUtils.toString(in); return (E) XmlUtils.unmarshalString(xml, Context.jc, type); } finally { in.close(); } }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void htmlEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage htmlMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("social", "pocket-money").build(), propertyBuilder, MAILBOX_ID); htmlMail.setModSeq(MOD_SEQ);/*from w w w .j a v a 2 s .co m*/ htmlMail.setUid(UID); assertThatJson(messageToElasticSearchJson.convertToJson(htmlMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/htmlMail.json"))); }