List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test(expected = NullPointerException.class) public void emailWithNoMailboxIdShouldThrow() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage mailWithNoMailboxId;/*from w w w. j a v a 2s .c o m*/ try { mailWithNoMailboxId = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, null); mailWithNoMailboxId.setModSeq(MOD_SEQ); mailWithNoMailboxId.setUid(UID); } catch (Exception exception) { throw Throwables.propagate(exception); } messageToElasticSearchJson.convertToJson(mailWithNoMailboxId, ImmutableList.of(new MockMailboxSession("username").getUser())); }
From source file:org.apache.james.jmap.model.MessageFactoryTest.java
@Test public void attachmentsShouldBeRetrievedWhenSome() throws Exception { String payload = "payload"; BlobId blodId = BlobId.of("id1"); String type = "content"; Attachment expectedAttachment = Attachment.builder().blobId(blodId).size(payload.length()).type(type) .cid("cid").isInline(true).build(); MetaDataWithContent testMail = MetaDataWithContent.builder().uid(2).flags(new Flags(Flag.SEEN)).size(0) .internalDate(INTERNAL_DATE) .content(new ByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml")))) .attachments(ImmutableList.of(MessageAttachment.builder() .attachment(org.apache.james.mailbox.model.Attachment.builder() .attachmentId(AttachmentId.from(blodId.getRawValue())).bytes(payload.getBytes()) .type(type).build()) .cid(Cid.from("cid")).isInline(true).build())) .mailboxId(MAILBOX_ID).messageId(MessageId.of("user|box|2")).build(); Message testee = messageFactory.fromMetaDataWithContent(testMail); assertThat(testee.getAttachments()).hasSize(1); assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment); }
From source file:org.openengsb.itests.util.AbstractExamTestHelper.java
public static Option[] baseConfiguration() throws Exception { String loglevel = LOG_LEVEL;/*from www .j a v a 2 s . co m*/ String debugPort = Integer.toString(DEBUG_PORT); boolean hold = true; boolean debug = false; InputStream paxLocalStream = ClassLoader.getSystemResourceAsStream("itests.local.properties"); if (paxLocalStream != null) { Properties properties = new Properties(); properties.load(paxLocalStream); loglevel = (String) ObjectUtils.defaultIfNull(properties.getProperty("loglevel"), loglevel); debugPort = (String) ObjectUtils.defaultIfNull(properties.getProperty("debugport"), debugPort); debug = ObjectUtils.equals(Boolean.TRUE.toString(), properties.getProperty("debug")); hold = ObjectUtils.equals(Boolean.TRUE.toString(), properties.getProperty("hold")); } Properties portNames = new Properties(); InputStream portsPropertiesFile = ClassLoader.getSystemResourceAsStream("ports.properties"); if (portsPropertiesFile == null) { throw new IllegalStateException("ports-configuration not found"); } portNames.load(portsPropertiesFile); LOGGER.warn("running itests with the following port-config"); LOGGER.warn(portNames.toString()); LogLevel realLogLevel = transformLogLevel(loglevel); Option[] mainOptions = new Option[] { new VMOption("-Xmx2048m"), new VMOption("-XX:MaxPermSize=256m"), karafDistributionConfiguration().frameworkUrl(maven().groupId("org.openengsb.framework") .artifactId("openengsb-framework").type("zip").versionAsInProject()), logLevel(realLogLevel), editConfigurationFilePut(WebCfg.HTTP_PORT, (String) portNames.get("jetty.http.port")), editConfigurationFilePut(ManagementCfg.RMI_SERVER_PORT, (String) portNames.get("rmi.server.port")), editConfigurationFilePut(ManagementCfg.RMI_REGISTRY_PORT, (String) portNames.get("rmi.registry.port")), editConfigurationFilePut( new ConfigurationPointer("etc/org.openengsb.infrastructure.jms.cfg", "openwire"), (String) portNames.get("jms.openwire.port")), editConfigurationFilePut( new ConfigurationPointer("etc/org.openengsb.infrastructure.jms.cfg", "stomp"), (String) portNames.get("jms.stomp.port")), mavenBundle(maven().groupId("org.openengsb.wrapped").artifactId("net.sourceforge.htmlunit-all") .versionAsInProject()) }; if (debug) { return combine(mainOptions, debugConfiguration(debugPort, hold)); } return mainOptions; }
From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java
@Test public void getMessageListUnreadFilterShouldWork() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); ComposedMessageId messageNotRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageRead = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.SEEN)); await();// w w w . jav a 2 s . c o m given().header("Authorization", accessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"isUnread\":\"true\"}}, \"#0\"]]").when().post("/jmap") .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds", allOf(containsInAnyOrder(messageNotRead.getMessageId().serialize()), not(containsInAnyOrder(messageRead.getMessageId().serialize())))); }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException { // Given/*w ww . ja v a2 s. co m*/ MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID, null, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))), new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(), propertyBuilder, MAILBOX_ID); mailWithNoInternalDate.setModSeq(MOD_SEQ); mailWithNoInternalDate.setUid(UID); // When MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser())); // Then assertThatJson(convertToJson).when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json"))); }
From source file:org.smurn.jply.lwjgldemo.LWJGLDemo.java
/** * Loads the vertex and fragment shader. *///from w ww .j a v a2 s . c o m private static int createShaders() throws IOException { // load and compile the vertex shader. String vertexShaderCode = IOUtils.toString(ClassLoader.getSystemResourceAsStream("vertexShader.glsl")); int vertexShaderId = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); glShaderSourceARB(vertexShaderId, vertexShaderCode); glCompileShaderARB(vertexShaderId); printLogInfo(vertexShaderId); // load and compile the fragment shader. String fragmentShaderCode = IOUtils.toString(ClassLoader.getSystemResourceAsStream("fragmentShader.glsl")); int fragmentShaderId = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); glShaderSourceARB(fragmentShaderId, fragmentShaderCode); glCompileShaderARB(fragmentShaderId); printLogInfo(fragmentShaderId); // combine the two into a program. int programId = ARBShaderObjects.glCreateProgramObjectARB(); glAttachObjectARB(programId, vertexShaderId); glAttachObjectARB(programId, fragmentShaderId); glValidateProgramARB(programId); glLinkProgramARB(programId); printLogInfo(programId); return programId; }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testPDFConfig() throws Exception { Response response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain") .put(ClassLoader.getSystemResourceAsStream("testPDFTwoTextBoxes.pdf")); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); responseMsg = responseMsg.replaceAll("[\r\n ]+", " ").trim(); assertEquals("Left column line 1 Right column line 1 Left colu mn line 2 Right column line 2", responseMsg); response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain") .header(TikaResource.X_TIKA_PDF_HEADER_PREFIX + "sortByPosition", "false") .put(ClassLoader.getSystemResourceAsStream("testPDFTwoTextBoxes.pdf")); responseMsg = getStringFromInputStream((InputStream) response.getEntity()); responseMsg = responseMsg.replaceAll("[\r\n ]+", " ").trim(); assertEquals("Left column line 1 Left column line 2 Right column line 1 Right column line 2", responseMsg); //make sure that default reverts to initial config option response = WebClient.create(endPoint + TIKA_PATH).type("application/pdf").accept("text/plain") .put(ClassLoader.getSystemResourceAsStream("testPDFTwoTextBoxes.pdf")); responseMsg = getStringFromInputStream((InputStream) response.getEntity()); responseMsg = responseMsg.replaceAll("[\r\n ]+", " ").trim(); assertEquals("Left column line 1 Right column line 1 Left colu mn line 2 Right column line 2", responseMsg); }
From source file:org.araqne.main.Araqne.java
/** * Fetch all default packages provided by JavaSE 1.6 environment. All OSGi * bundles can use JavaSE packages naturally by doing this. Some OSGi and * logging related packages also included. * // w ww . j a v a2s .c o m * @return the whole concatenated list of system packages. * @throws FileNotFoundException */ private String getSystemPackages() throws FileNotFoundException { StringBuffer buffer = new StringBuffer(4096); BufferedReader reader = new BufferedReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream("system.packages"))); String s = null; try { while ((s = reader.readLine()) != null) { buffer.append(s); } } catch (IOException e) { e.printStackTrace(); } return buffer.toString(); }
From source file:org.apache.hadoop.gateway.GatewayFuncTestDriver.java
public InputStream getResourceStream(String resource) throws IOException { InputStream stream = null;/*from w w w . jav a 2 s .com*/ if (resource.startsWith("file:/")) { try { stream = FileUtils.openInputStream(new File(new URI(resource))); } catch (URISyntaxException e) { throw new IOException(e); } } else { stream = ClassLoader.getSystemResourceAsStream(getResourceName(resource)); } assertThat("Failed to find test resource " + resource, stream, Matchers.notNullValue()); return stream; }
From source file:fi.aalto.drumbeat.GUIDConverter.java
private void convert(ColumnNamesModeConversionOptions options) { CsvToBean<GenericLinkBean> csvToBean = new CsvToBean<GenericLinkBean>(); Map<String, String> columnMapping = new HashMap<String, String>(); columnMapping.put("guid", options.getSubjectElementGUID_columnName()); columnMapping.put("connected_guid", options.getCorrespondingObjectGUID_columnName()); HeaderColumnNameTranslateMappingStrategy<GenericLinkBean> strategy = new HeaderColumnNameTranslateMappingStrategy<GenericLinkBean>(); strategy.setType(GenericLinkBean.class); strategy.setColumnMapping(columnMapping); List<GenericLinkBean> list = null; System.out.println("input file name: " + options.getInputFile()); CSVReader reader = new CSVReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream(options.getInputFile()))); list = csvToBean.parse(strategy, reader); for (GenericLinkBean gb : list) System.out.println(gb);//from ww w .j a va 2s . c o m //TODO varmista, ett column namet ovat olemassa! writeTurtleFile(options, list); }