本文整理汇总了Java中com.google.common.io.Resources类的典型用法代码示例。如果您正苦于以下问题:Java Resources类的具体用法?Java Resources怎么用?Java Resources使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resources类属于com.google.common.io包,在下文中一共展示了Resources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.google.common.io.Resources; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final String k2 = "org/apache/drill/Pickle.class";
final URL url = Resources.getResource(k2);
final byte[] clazz = Resources.toByteArray(url);
final ClassReader cr = new ClassReader(clazz);
final ClassWriter cw = writer();
final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);
final byte[] output = cw.toByteArray();
Files.write(output, new File("/src/scratch/bytes/S.class"));
check(output);
final DrillConfig c = DrillConfig.forClient();
final SystemOptionManager m = new SystemOptionManager(c, new LocalPStoreProvider(c));
m.init();
try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
clz.getMethod("x").invoke(null);
}
}
示例2: generateArclibXmlNestedElementMapping
import com.google.common.io.Resources; //导入依赖的package包/类
/**
* Tests that also the child elements have been created at the destination xpath when the source element is nested
*/
@Test
public void generateArclibXmlNestedElementMapping() throws SAXException, ParserConfigurationException, XPathExpressionException,
IOException,
TransformerException {
SipProfile profile = new SipProfile();
String sipProfileXml = Resources.toString(this.getClass().getResource(
"/arclibxmlgeneration/sipProfiles/sipProfileNestedElementMapping.xml"), StandardCharsets
.UTF_8);
profile.setXml(sipProfileXml);
store.save(profile);
String arclibXml = generator.generateArclibXml(SIP_PATH, profile.getId());
assertThat(arclibXml, is(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<METS:mets xmlns:METS=\"http://www.loc.gov/METS/\"><METS:metsHdr CREATEDATE=\"2013-01-22T10:55:20Z\" ID=\"kpw01169310\" LASTMODDATE=\"2013-01-22T10:55:20Z\" RECORDSTATUS=\"COMPLETE\">\r\n\t\t<METS:agent ROLE=\"CREATOR\" TYPE=\"ORGANIZATION\"> \r\n\t\t\t<METS:name>Exon s.r.o.</METS:name>\r\n\t\t</METS:agent>\r\n\t\t<METS:agent ROLE=\"ARCHIVIST\" TYPE=\"ORGANIZATION\"> \r\n\t\t\t<METS:name>ZLG001</METS:name>\r\n\t\t</METS:agent>\r\n\t</METS:metsHdr>\r\n</METS:mets>"));
}
示例3: call
import com.google.common.io.Resources; //导入依赖的package包/类
@Override
public String call() throws Exception
{
try
{
final URL resource = Resources.getResource("configurable.txt");
final File f = new File(resource.toURI());
if( !f.exists() )
{
return NO_CONTENT;
}
if( lastMod == 0 || lastMod < f.lastModified() )
{
final CharSource charSource = Resources.asCharSource(resource, Charset.forName("utf-8"));
final StringWriter sw = new StringWriter();
charSource.copyTo(sw);
lastContent = sw.toString();
lastMod = f.lastModified();
}
return lastContent;
}
catch( Exception e )
{
return NO_CONTENT;
}
}
示例4: generateArclibXmlElementAtPositionMapping
import com.google.common.io.Resources; //导入依赖的package包/类
/**
* Tests that only single element has been created at the destination xPath when specifying the position of the source element
*/
@Test
public void generateArclibXmlElementAtPositionMapping() throws SAXException, ParserConfigurationException, XPathExpressionException,
IOException,
TransformerException {
SipProfile profile = new SipProfile();
String sipProfileXml = Resources.toString(this.getClass().getResource(
"/arclibxmlgeneration/sipProfiles/sipProfileElementAtPositionMapping.xml"), StandardCharsets
.UTF_8);
profile.setXml(sipProfileXml);
store.save(profile);
String arclibXml = generator.generateArclibXml(SIP_PATH, profile.getId());
assertThat(arclibXml, is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<METS:mets xmlns:METS=\"http://www.loc.gov/METS/\"><METS:metsHdr xmlns:METS=\"http://arclib.lib.cas.cz/ARCLIB_XML\"><METS:agent ROLE=\"CREATOR\" TYPE=\"ORGANIZATION\"> \r\n\t\t\t<METS:name>Exon s.r.o.</METS:name>\r\n\t\t</METS:agent>\r\n</METS:metsHdr></METS:mets>"));
}
示例5: prepareCompTypes
import com.google.common.io.Resources; //导入依赖的package包/类
private void prepareCompTypes(Set<String> neededTypes) {
try {
JSONArray buildInfo = new JSONArray(Resources.toString(
Compiler.class.getResource(COMP_BUILD_INFO), Charsets.UTF_8));
Set<String> allSimpleTypes = Sets.newHashSet();
for (int i = 0; i < buildInfo.length(); ++i) {
JSONObject comp = buildInfo.getJSONObject(i);
allSimpleTypes.add(comp.getString("type"));
}
simpleCompTypes = Sets.newHashSet(neededTypes);
simpleCompTypes.retainAll(allSimpleTypes);
extCompTypes = Sets.newHashSet(neededTypes);
extCompTypes.removeAll(allSimpleTypes);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: get
import com.google.common.io.Resources; //导入依赖的package包/类
private CompilationUnit get(Class<?> c) throws IOException {
URL u = getSourceURL(c);
try (Reader reader = Resources.asCharSource(u, UTF_8).openStream()) {
String body = CharStreams.toString(reader);
// TODO: Hack to remove annotations so Janino doesn't choke. Need to reconsider this problem...
body = body.replaceAll("@\\w+(?:\\([^\\\\]*?\\))?", "");
for(Replacement r : REPLACERS){
body = r.apply(body);
}
// System.out.println("original");
// System.out.println(body);;
// System.out.println("decompiled");
// System.out.println(decompile(c));
try {
return new Parser(new Scanner(null, new StringReader(body))).parseCompilationUnit();
} catch (CompileException e) {
logger.warn("Failure while parsing function class:\n{}", body, e);
return null;
}
}
}
示例7: testReservedWordsHandling
import com.google.common.io.Resources; //导入依赖的package包/类
@Test
public final void testReservedWordsHandling() throws Exception {
Path outputPath = testDir.resolve("output");
Files.createDirectories(outputPath);
RDF4JSchemaGeneratorCore testBuilder = new RDF4JSchemaGeneratorCore(Resources.getResource("oa.ttl").getPath(), "text/turtle");
Path javaFilePath = outputPath.resolve("OA.java");
testBuilder.generate(javaFilePath);
assertTrue("Java file was not found", Files.exists(javaFilePath));
assertTrue("Java file was empty", Files.size(javaFilePath) > 0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Files.copy(javaFilePath, out);
String result = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue(result.contains("public static final IRI hasTarget"));
assertTrue(result.contains("public static final IRI _default"));
}
示例8: TODO
import com.google.common.io.Resources; //导入依赖的package包/类
@Ignore // TODO(DRILL-2326) remove this when we get rid of the scalar replacement option test cases below
@Test
public void testBigIntVarCharReturnTripConvertLogical() throws Exception {
final String logicalPlan = Resources.toString(
Resources.getResource(CONVERSION_TEST_LOGICAL_PLAN), Charsets.UTF_8);
final List<QueryDataBatch> results = testLogicalWithResults(logicalPlan);
int count = 0;
final RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
for (QueryDataBatch result : results) {
count += result.getHeader().getRowCount();
loader.load(result.getHeader().getDef(), result.getData());
if (loader.getRecordCount() > 0) {
VectorUtil.showVectorAccessibleContent(loader);
}
loader.clear();
result.release();
}
assertTrue(count == 10);
}
示例9: setUp
import com.google.common.io.Resources; //导入依赖的package包/类
@Before
public void setUp() throws IOException, URISyntaxException {
// Gets the test resource files.
Path fileA = Paths.get(Resources.getResource("fileA").toURI());
Path fileB = Paths.get(Resources.getResource("fileB").toURI());
Path directoryA = Paths.get(Resources.getResource("directoryA").toURI());
expectedFileAString = new String(Files.readAllBytes(fileA), StandardCharsets.UTF_8);
expectedFileBString = new String(Files.readAllBytes(fileB), StandardCharsets.UTF_8);
// Prepares a test TarStreamBuilder.
testTarStreamBuilder.addEntry(
new TarArchiveEntry(fileA.toFile(), "some/path/to/resourceFileA"));
testTarStreamBuilder.addEntry(new TarArchiveEntry(fileB.toFile(), "crepecake"));
testTarStreamBuilder.addEntry(new TarArchiveEntry(directoryA.toFile(), "some/path/to"));
}
示例10: executeSchemaCql
import com.google.common.io.Resources; //导入依赖的package包/类
public static void executeSchemaCql(Session session, boolean deleteData) {
try {
URL schema = Resources.getResource("schema.cql");
String schemaCql = Resources.toString(schema, Charset.forName("UTF-8"));
schemaCql = schemaCql.replaceAll("(?m)//.*$", "");
String[] statements = schemaCql.split(";");
if (deleteData) {
dropSchema(session);
}
for (String statement : statements) {
statement = statement.trim();
if (statement.isEmpty()) continue;
executeWithLog(session, statement);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: testUserPassword
import com.google.common.io.Resources; //导入依赖的package包/类
@Test
public void testUserPassword() throws Exception {
startServer(buildUserPasswordConfig());
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("oryx", "pass".toCharArray());
}
});
try {
String response = Resources.toString(
new URL("http://localhost:" + getHTTPPort() + "/helloWorld"),
StandardCharsets.UTF_8);
assertEquals("Hello, World", response);
} finally {
Authenticator.setDefault(null);
}
}
示例12: generateContent
import com.google.common.io.Resources; //导入依赖的package包/类
@VisibleForTesting
String generateContent(final URL staticFile, final Api api) throws IOException {
final ST st = getStGroup(staticFile);
final String fileName = new File(staticFile.getPath()).getName();
st.add("api", new ApiGenModel(api));
if (fileName.equals("collection.json.stg")) {
st.add("id", "f367b534-c9ea-e7c5-1f46-7a27dc6a30ba");
final String readme = getStGroup(Resources.getResource("templates/postman/README.md.stg")).render();
st.add("readme", readme);
}
if (fileName.equals("template.json.stg")) {
st.add("id", "5bb74f05-5e78-4aee-b59e-492c947bc160");
}
return st.render();
}
示例13: sampleWordpressDump
import com.google.common.io.Resources; //导入依赖的package包/类
@Test
public void sampleWordpressDump() throws IOException, DocumentException {
try (Reader reader = new InputStreamReader(Resources.asByteSource(Resources.getResource(getClass(), "wordpress-sample-rss.xml")).openBufferedStream())) {
WordpressRss wordpressRss = WordpressRssConverter.build(XmlParser.of(reader));
System.out.println("------------------------");
System.out.println(wordpressRss);
System.out.println("------------------------");
ImmutableList<Document> documents = WordpressRss2Solid.convert(wordpressRss);
documents.forEach(doc -> {
String docAsString = doc.toString();
int idx = docAsString.indexOf("---");
if (idx!=-1) {
int idxE = docAsString.indexOf("---", idx+3);
if (idxE!=-1) {
docAsString=docAsString.substring(0, idxE+3);
}
}
System.out.println(docAsString);
});
System.out.println("------------------------");
}
}
示例14: addingBundle
import com.google.common.io.Resources; //导入依赖的package包/类
@Override
public Boolean addingBundle(final Bundle bundle, final BundleEvent event) {
URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event);
if (resource != null) {
try {
for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
registerFactory(factoryClassName, bundle);
}
return Boolean.TRUE;
} catch (final IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
}
return Boolean.FALSE;
}
示例15: getProps
import com.google.common.io.Resources; //导入依赖的package包/类
/**
* create a Properties object use the config file
* @param configFile a file path
* @return Properties object
* @throws Exception
*/
public static Properties getProps(String configFile) throws IOException {
//InputStream is = getClass().getClassLoader().getResourceAsStream(configFile);
InputStream is = null;
try {
is = Resources.getResource(configFile).openStream();
Properties props = new Properties();
props.load(is);
return props;
} finally {
if (is != null) {
is.close();
}
}
}