List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.kuali.kfs.sys.CSVDataLoader.java
public void loadData(String resourceName, boolean quoted) { BufferedReader reader = null; try {/* w ww . j a v a 2s.c o m*/ InputStream systemResourceAsStream = ClassLoader.getSystemResourceAsStream(resourceName); reader = new BufferedReader(new InputStreamReader(systemResourceAsStream)); String line = null; String[] dataCols = null; int headerPos = 0; int pos = -1; while ((line = reader.readLine()) != null) { if (quoted) { dataCols = parseQuoted(line, ","); } else { dataCols = line.split(",", -1); } if (pos == -1) { for (String hdr : dataCols) { headerMap.put(hdr.trim().toUpperCase(), headerPos++); } } else { dataMap.put(String.valueOf(pos), dataCols); } pos++; } } catch (Exception e) { throw new RuntimeException(e); } finally { if (reader != null) { try { reader.close(); reader = null; } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testTextMainMultipart() throws Exception { //boilerpipe//from ww w. j a v a 2 s . co m Attachment attachmentPart = new Attachment("myhtml", "text/html", ClassLoader.getSystemResourceAsStream("testHTML.html")); Response response = WebClient.create(endPoint + TIKA_PATH + "/form/main").type("multipart/form-data") .accept("text/plain").post(attachmentPart); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("Title : Test Indexation Html")); assertFalse(responseMsg.contains("Indexation du fichier")); }
From source file:barrysw19.calculon.fics.FICSInterface.java
private FICSInterface() { Digester digester = new Digester(); digester.addObjectCreate("calculon/fics", FICSConfig.class); digester.addBeanPropertySetter("calculon/fics/operator-name", "operatorName"); digester.addBeanPropertySetter("calculon/fics/login-name", "loginName"); digester.addBeanPropertySetter("calculon/fics/accept-min", "acceptMin"); digester.addBeanPropertySetter("calculon/fics/accept-max", "acceptMax"); digester.addBeanPropertySetter("calculon/fics/max-rematches", "maxRematches"); digester.addBeanPropertySetter("calculon/fics/reseek", "reseek"); digester.addObjectCreate("calculon/fics/default-seeks/seek", FICSConfig.Seek.class); digester.addSetProperties("calculon/fics/default-seeks/seek", "time", "initialTime"); digester.addSetProperties("calculon/fics/default-seeks/seek", "inc", "increment"); digester.addSetNext("calculon/fics/default-seeks/seek", "addSeekAd"); try {//from w w w . j a va 2 s .co m ficsConfig = (FICSConfig) digester.parse(ClassLoader.getSystemResourceAsStream("calculon.xml")); } catch (Exception e) { log.log(Level.WARNING, "Config reading failed", e); throw new RuntimeException(e); } log.fine(ficsConfig.toString()); openingBook = OpeningBook.getDefaultBook(); listeners.add(new DebugListener()); listeners.add(new ChallengeListener()); listeners.add(new BoardListener()); listeners.add(new AbortListener()); listeners.add(new CommandListener()); listeners.add(new GameEndedListener()); listeners.add(new ReseekListener()); listeners.add(new ChatListener()); listeners.add(new BlockListener()); }
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void testDocWAV() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).type(APPLICATION_MSWORD) .accept("application/zip").put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV)); Map<String, String> data = readZipArchive((InputStream) response.getEntity()); assertEquals(WAV1_MD5, data.get(WAV1_NAME)); assertEquals(WAV2_MD5, data.get(WAV2_NAME)); assertFalse(data.containsKey(UnpackerResource.TEXT_FILENAME)); }
From source file:test.SecureSampleApp.java
private static PublicKey readPublicKey() throws IOException { InputStream publicKeyResource = ClassLoader.getSystemResourceAsStream("public.key.data"); byte[] publicKeyData = IOUtils.toByteArray(publicKeyResource); PublicKey publicKey = CipherUtils.deserializePublicKey(publicKeyData, "RSA"); return publicKey; }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void documentWithBadDeclaredMetadataShouldBeWellHandled() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/fake.txt"); assertThat(inputStream).isNotNull(); assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.text") .getTextualContent()).contains("This is an awesome document on libroffice writter!\n"); }
From source file:org.obm.push.arquillian.ManagedTomcatInstaller.java
private static void copyTomcatManager() throws IOException, ArchiveException { InputStream asStream = ClassLoader.getSystemResourceAsStream(TOMCAT_MANAGER_RESOURCE); File tarFile = uncompressBZ2File(asStream); File tomcatWebapps = new File(TOMCAT_TEMPORARY_VERSION_FOLDER, "webapps/"); uncompressTarFile(tomcatWebapps, tarFile); }
From source file:barrysw19.calculon.icc.ICCInterface.java
private ICCInterface() { Digester digester = new Digester(); digester.addObjectCreate("calculon/icc", ICCSConfig.class); digester.addBeanPropertySetter("calculon/icc/operator-name", "operatorName"); digester.addBeanPropertySetter("calculon/icc/login-name", "loginName"); digester.addBeanPropertySetter("calculon/icc/accept-min", "acceptMin"); digester.addBeanPropertySetter("calculon/icc/accept-max", "acceptMax"); digester.addBeanPropertySetter("calculon/icc/max-rematches", "maxRematches"); digester.addBeanPropertySetter("calculon/icc/reseek", "reseek"); digester.addBeanPropertySetter("calculon/icc/formula", "formula"); digester.addObjectCreate("calculon/icc/default-seeks/seek", ICCSConfig.Seek.class); digester.addSetProperties("calculon/icc/default-seeks/seek", "time", "initialTime"); digester.addSetProperties("calculon/icc/default-seeks/seek", "inc", "increment"); digester.addSetNext("calculon/icc/default-seeks/seek", "addSeekAd"); try {//from w ww.j a v a 2s .com iccConfig = (ICCSConfig) digester.parse(ClassLoader.getSystemResourceAsStream("calculon.xml")); } catch (Exception e) { LOG.warn("Config reading failed", e); throw new RuntimeException(e); } LOG.trace(iccConfig.toString()); openingBook = OpeningBook.getDefaultBook(); listeners.add(new DebugListener()); listeners.add(new ChallengeListener()); listeners.add(new BoardListener()); listeners.add(new AbortListener()); listeners.add(new CommandListener()); listeners.add(new ReseekListener()); listeners.add(new ChatListener()); listeners.add(new BlockLv2Listener()); blockHandlers.add(new GameStartedHandler()); blockHandlers.add(new GameEndedHandler()); blockHandlers.add(new ClockUpdateHandler()); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);//from w w w . j a v a2 s . c o m assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }
From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java
@Test public void shouldThrowOnEmptyFilterName() throws Exception { HierarchicalConfiguration configuration = loadConfiguration( ClassLoader.getSystemResourceAsStream("emptyfiltername.xml")); assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)) .isInstanceOf(ConfigurationException.class); }