List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.loadsimulator.jmetertest.jmetertest.AMSJMeterLoadTest.java
private static List<GetMetricRequestInfo> readMetricsFromFile(String app) { InputStream input = null;/*ww w . j av a 2s. co m*/ List<GetMetricRequestInfo> metricList = new ArrayList<>(); String fileName = "ui_metrics_def/" + app + ".dat"; try { input = ClassLoader.getSystemResourceAsStream(fileName); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); String line; List<String> metrics = new ArrayList<>(); while ((line = reader.readLine()) != null) { if (line.startsWith("|")) { boolean needsTimestamps = line.contains("startTime"); boolean needsHost = line.contains("hostname"); metricList.add(new GetMetricRequestInfo(metrics, needsTimestamps, needsHost)); metrics.clear(); } else { metrics.add(line); } } return metricList; } catch (IOException e) { LOG.error("Cannot read file " + fileName + " for appID " + app, e); } finally { if (input != null) { try { input.close(); } catch (IOException ex) { } } } return null; }
From source file:org.stem.IntegrationTestBase.java
private void loadSchema() { cassandraTestSession.execute("DROP KEYSPACE IF EXISTS stem"); InputStream inputStream = ClassLoader.getSystemResourceAsStream("schema.cql"); if (null == inputStream) throw new NullPointerException("Input stream for Schema file can not be null"); List<String> lines = getLines(inputStream); List<String> statements = linesToCQLStatements(lines); for (String statement : statements) { cassandraTestSession.execute(statement); }/* w w w . j a v a 2s . co m*/ }
From source file:co.rsk.peg.RepositoryBlockStoreTest.java
@Test public void test() throws Exception { // This Is how I produced RepositoryBlockStore_data.ser. I had a bitcoind in regtest with 613 blocks + genesis block // NetworkParameters params = RegTestParams.get(); // Context context = new Context(params); // Wallet wallet = new Wallet(context); // BlockStore store = new SPVBlockStore(params, new File("spvBlockstore")); // AbstractBlockChain chain = new BlockChain(context, wallet, store); // PeerGroup peerGroup = new PeerGroup(context, chain); // peerGroup.start(); // final DownloadProgressTracker listener = new DownloadProgressTracker(); // peerGroup.startBlockChainDownload(listener); // listener.await(); // peerGroup.stop(); // StoredBlock storedBlock = chain.getChainHead(); // FileOutputStream fos = new FileOutputStream("RepositoryBlockStore_data.ser"); // ObjectOutputStream oos = new ObjectOutputStream(fos); // for (int i = 0; i < 614; i++) { // Triple<byte[], BigInteger , Integer> tripleStoredBlock = new ImmutableTriple<>(storedBlock.getHeader().bitcoinSerialize(), storedBlock.getChainWork(), storedBlock.getHeight()); // oos.writeObject(tripleStoredBlock); // storedBlock = store.get(storedBlock.getHeader().getPrevBlockHash()); // }//from ww w . jav a 2 s. c o m // oos.close(); // Read original store InputStream fileInputStream = ClassLoader.getSystemResourceAsStream("peg/RepositoryBlockStore_data.ser"); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); Repository repository = new RepositoryImplForTesting(); RepositoryBlockStore store = new RepositoryBlockStore(repository, PrecompiledContracts.BRIDGE_ADDR); for (int i = 0; i < 614; i++) { Triple<byte[], BigInteger, Integer> tripleStoredBlock = (Triple<byte[], BigInteger, Integer>) objectInputStream .readObject(); BtcBlock header = RegTestParams.get().getDefaultSerializer().makeBlock(tripleStoredBlock.getLeft()); StoredBlock storedBlock = new StoredBlock(header, tripleStoredBlock.getMiddle(), tripleStoredBlock.getRight()); if (i == 0) { store.setChainHead(storedBlock); } store.put(storedBlock); } // Create a new instance of the store RepositoryBlockStore store2 = new RepositoryBlockStore(repository, PrecompiledContracts.BRIDGE_ADDR); // Check a specific block that used to fail when we had a bug assertEquals(store.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")), store2.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a"))); //Check new instance content is identical to the original one StoredBlock storedBlock = store.getChainHead(); StoredBlock storedBlock2 = store2.getChainHead(); int headHeight = storedBlock.getHeight(); for (int i = 0; i < headHeight; i++) { assertNotNull(storedBlock); assertEquals(storedBlock, storedBlock2); Sha256Hash prevBlockHash = storedBlock.getHeader().getPrevBlockHash(); storedBlock = store.get(prevBlockHash); storedBlock2 = store2.get(prevBlockHash); } }
From source file:org.apache.tika.server.TikaResourceTest.java
@Test public void testSimpleWord() throws Exception { Response response = WebClient.create(endPoint + TIKA_PATH).type("application/msword").accept("text/plain") .put(ClassLoader.getSystemResourceAsStream(TEST_DOC)); String responseMsg = getStringFromInputStream((InputStream) response.getEntity()); assertTrue(responseMsg.contains("test")); }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void textMicrosoftWorldTest() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/writter.docx"); assertThat(inputStream).isNotNull(); assertThat(textExtractor/*from w w w. j av a2 s. c om*/ .extractContent(inputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") .getTextualContent()).contains("This is an awesome document on libroffice writter!\n"); }
From source file:facebook4j.internal.http.MockHttpClientWrapper.java
private String readMockJSON() throws FacebookException { try {//from w ww . j a va 2s .co m InputStream is = ClassLoader.getSystemResourceAsStream(mockJSONResourceName); if (null == is) return null; BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while (null != (line = reader.readLine())) { sb.append(line); } return sb.toString(); } catch (IOException e) { throw new FacebookException("cannot read mock json", e); } }
From source file:org.apromore.canoniser.epml.AbstractTest.java
/** * @param resource the name of a resource within both the <code>CPF/</code> and <code>ANF/</code> directories of the classpath, minus * the respective <code>.cpf</code> and <code>.anf</code> extensions *//*from w ww . j a v a 2s . c o m*/ public void testDeCanonise(final String resource) throws CanoniserException, JAXBException, SAXException, IOException { EPML20Canoniser c = new EPML20Canoniser(); try (OutputStream epmlStream = new FileOutputStream(new File("target/" + resource + ".epml")); InputStream cpfStream = ClassLoader.getSystemResourceAsStream("CPF/" + resource + ".cpf"); InputStream anfStream = ClassLoader.getSystemResourceAsStream("ANF/" + resource + ".anf");) { c.deCanonise(CPFSchema.unmarshalCanonicalFormat(cpfStream, true).getValue(), ANFSchema.unmarshalAnnotationFormat(anfStream, true).getValue(), epmlStream, new PluginRequestImpl()); epmlStream.flush(); } }
From source file:org.openmrs.contrib.liquibaserunner.LiquibaseRunner.java
/** * @param changeLogFile//from w w w. j a v a 2s.co m * @return * @throws IOException * @throws FileNotFoundException */ private String createTempChangeLogFile(final String changeLogFile) throws IOException { InputStream input = null; OutputStream output = null; File tempFile = null; try { input = ClassLoader.getSystemResourceAsStream("sqlfile-changeset.xml"); String changeset = IOUtils.toString(input, "UTF-8"); input.close(); changeset = changeset.replace("${sqlfile}", changeLogFile); tempFile = File.createTempFile("liquibaserunner", ".xml"); output = new FileOutputStream(tempFile); IOUtils.write(changeset, output, "UTF-8"); output.close(); return tempFile.getAbsolutePath(); } finally { if (tempFile != null) { tempFile.deleteOnExit(); } IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } }
From source file:com.octo.mbo.data.Pptx4JUpdatablePackageTest.java
@Test public void saveChangesTest() throws CopyNotesException, InvalidFormatException, Pptx4jException, IOException, JAXBException { InputStream testFileStream = ClassLoader.getSystemResourceAsStream("pptx-test.pptx"); byte[] inputBytes = IOUtils.toByteArray(testFileStream); //In order to read it again ByteArrayInputStream testStream = new ByteArrayInputStream(inputBytes); Pptx4jPackageFactory factory = new Pptx4jPackageFactory(); Pptx4jPackage pptx4jPackage = factory.loadPackage(null, testStream); SlidePart slidePart = new SlidePart(new PartName("/ppt/slides/slide3.xml")); slidePart.setContents(SlidePart.createSld()); pptx4jPackage.pMLpkg.getMainPresentationPart().addSlide(2, slidePart); //This pptx will be invalid but the test is ok if the output file is different from the input file ByteArrayOutputStream outputValue = new ByteArrayOutputStream(); pptx4jPackage.saveChanges(outputValue); byte[] outputBytes = outputValue.toByteArray(); Assert.assertNotEquals(inputBytes, outputBytes); }
From source file:ws.moor.bt.BitThief.java
private static void configureStaticStuff(BitThiefConfiguration configuration) throws IOException { InputStream stream = ClassLoader.getSystemResourceAsStream(configuration.getLoggingPropertyFile()); if (stream != null) { Properties properties = new Properties(); properties.load(stream);//from w ww. jav a 2 s . c om PropertyConfigurator.configure(properties); } else { System.err.println("unable to load logging property file"); System.exit(1); } }