当前位置: 首页>>代码示例>>Java>>正文


Java Resources.toByteArray方法代码示例

本文整理汇总了Java中com.google.common.io.Resources.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.toByteArray方法的具体用法?Java Resources.toByteArray怎么用?Java Resources.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.Resources的用法示例。


在下文中一共展示了Resources.toByteArray方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:25,代码来源:ReplaceMethodInvoke.java

示例2: testSuccessFile

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Test
public void testSuccessFile() throws Exception {
  Path p = new Path("/tmp/nation_test_parquet_scan");
  if (fs.exists(p)) {
    fs.delete(p, true);
  }

  fs.mkdirs(p);

  byte[] bytes = Resources.toByteArray(Resources.getResource("tpch/nation.parquet"));

  FSDataOutputStream os = fs.create(new Path(p, "nation.parquet"));
  os.write(bytes);
  os.close();
  fs.create(new Path(p, "_SUCCESS")).close();
  fs.create(new Path(p, "_logs")).close();

  testBuilder()
      .sqlQuery("select count(*) c from dfs.tmp.nation_test_parquet_scan where 1 = 1")
      .unOrdered()
      .baselineColumns("c")
      .baselineValues(25L)
      .build()
      .run();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:26,代码来源:TestParquetScan.java

示例3: getString

import com.google.common.io.Resources; //导入方法依赖的package包/类
protected String getString(String filePath) throws IOException {

		URL resource = Resources.getResource(filePath);
		Scanner scanner = new Scanner(new ByteArrayInputStream(Resources.toByteArray(resource)));
		StringBuilder stringBuilder = new StringBuilder();
		while (scanner.hasNextLine()) {
			stringBuilder.append(scanner.nextLine());
			stringBuilder.append("\n");
		}

		return stringBuilder.toString();
	}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:CompilerTest.java

示例4: resourceBytes

import com.google.common.io.Resources; //导入方法依赖的package包/类
public static byte[] resourceBytes(String path) throws IOException {
    try {
        URL url = Resources.getResource(path);
        return Resources.toByteArray(url);
    } catch (IllegalArgumentException ex) {
        throw new MissingObject("template", path);
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:9,代码来源:Utils.java

示例5: ConfigurationImpl

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Inject
public ConfigurationImpl(ConfigurationProperties properties) {
  this.properties = properties;

  callbackBaseUrl = addTrailingSlash(properties.callbackBaseUrl());
  LOGGER.debug("Callback Url: {}", callbackBaseUrl);

  nexmoCallbackBaseUrl = addTrailingSlash(properties.nexmoCallbackBaseUrl());
  LOGGER.debug("Nexmo callback Url: {}", nexmoCallbackBaseUrl);

  commsApiEndpoint = addTrailingSlash(properties.commsRouterUrl());
  LOGGER.debug("Comms Api Endpoint: {}", commsApiEndpoint);

  commsRouterId = properties.commsRouterId();

  phoneEndpoint = new VoiceEndpoint(properties.phone());
  LOGGER.debug("phoneEndpoint: {}", phoneEndpoint);

  try {
    String configPath = System.getProperty(PropertiesConfiguration.SYSTEM_PROPERTY_KEY);
    URL privateKeyFile = getFile(configPath, properties.appPrivateKey());
    byte[] privateKey = Resources.toByteArray(privateKeyFile);
    jwtAuthMethod = new JWTAuthMethod(properties.appId(), privateKey);
    LOGGER.debug("private key loaded from: {}", privateKeyFile);
  } catch (Exception e) {
    throw new RuntimeException("Can't read private key", e);
  }

  // set music on hold URL
  musicOnHoldUrl = properties.musicOnHoldUrl();
  
  commsQueueId = properties.commsQueueID();
  
  commsPlanId = properties.commsPlanID();
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:36,代码来源:ConfigurationImpl.java

示例6: load

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public byte[] load(String path) throws ClassTransformationException, IOException {
  URL u = this.getClass().getResource(path);
  if (u == null) {
    throw new ClassTransformationException(String.format("Unable to find TemplateClass at path %s", path));
  }
  return Resources.toByteArray(u);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:9,代码来源:ByteCodeLoader.java

示例7: open

import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public FSDataInputStream open(Path arg0, int arg1) throws IOException {
  String file = getFileName(arg0);
  URL url = Resources.getResource(file);
  if(url == null){
    throw new IOException(String.format("Unable to find path %s.", arg0.getName()));
  }
  ResourceInputStream ris = new ResourceInputStream(Resources.toByteArray(url));
  return new FSDataInputStream(ris);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:11,代码来源:ClassPathFileSystem.java

示例8: downloadSignedCodeblocksJar

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Returns a byte array containing the binary content of the signed
 * codeblocks jar.
 */
public static byte[] downloadSignedCodeblocksJar() throws IOException {
  // The codeblocks jar was signed at build time.
  // We expect the jar file to be in our class directory
  URL url = ResourceUtil.class.getResource(CODEBLOCKS_JAR);
  return Resources.toByteArray(url);
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:11,代码来源:ResourceUtil.java

示例9: propertiesFromUrl

import com.google.common.io.Resources; //导入方法依赖的package包/类
private static Properties propertiesFromUrl(URL propertiesUrl) {
  try (InputStream stream = new ByteArrayInputStream(Resources.toByteArray(propertiesUrl))) {
    return propertiesFromStream(stream);
  } catch (Exception e) {
    throw new RuntimeException("Failed to load properties from URL [" + propertiesUrl + "]", e);
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:8,代码来源:ConnectionResourcesBean.java

示例10: downloadStarterAppApk

import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
 * Returns a byte array containing the binary content of the starter app apk.
 */
public static byte[] downloadStarterAppApk() throws IOException {
  // We expect the start app apk file to be in our class directory
  return Resources.toByteArray(ResourceUtil.class.getResource(STARTER_APP_APK));
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:8,代码来源:ResourceUtil.java

示例11: getBufferedReaderFromResource

import com.google.common.io.Resources; //导入方法依赖的package包/类
private static BufferedReader getBufferedReaderFromResource(String path) throws IOException {
  InputStream stream = new ByteArrayInputStream(Resources.toByteArray(Resources.getResource(path)));
  return new BufferedReader(new InputStreamReader(stream));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:5,代码来源:TestMfsBlockLoader.java

示例12: addTaxCodes

import com.google.common.io.Resources; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test(groups = "fast")
public void addTaxCodes() throws IOException, ServletException, SQLException {
    // given
    byte[] data = Resources.toByteArray(Resources.getResource(getClass(), "tax-codes-01.json"));
    ByteArrayInputStream byis = new ByteArrayInputStream(data);
    ByteArrayOutputStream byos = givenDefaultServletCall("POST", "/taxCodes", byis, data.length,
            EasyTaxServlet.APPLICATION_JSON_UTF8);
    givenPermissions(TEST_USER, TEST_PASSWORD, TEST_PERMISSIONS);

    // when
    servlet.service(req, res);

    // then
    thenAuthenticatedAs(TEST_USER, TEST_PASSWORD);
    thenDefaultOkResponse();

    @SuppressWarnings("rawtypes")
    ArgumentCaptor<List> taxCodesCaptor = ArgumentCaptor.forClass(List.class);
    then(dao).should().saveTaxCodes(taxCodesCaptor.capture());

    assertEquals(byos.size(), 0, "Response body content");
    List<EasyTaxTaxCode> savedList = taxCodesCaptor.getValue();
    assertEquals(savedList.size(), 2, "Saved count");

    EasyTaxTaxCode saved = savedList.get(0);
    assertEquals(saved.getCreatedDate(), now);
    assertEquals(saved.getKbTenantId(), tenantId);
    assertEquals(saved.getTaxZone(), "NZ");
    assertEquals(saved.getProductName(), "memory-use");
    assertEquals(saved.getTaxCode(), "GST");
    assertDateTimeEquals(saved.getValidFromDate(),
            new DateTime(2017, 1, 1, 12, 0, 0, DateTimeZone.UTC), "Valid from date");
    assertDateTimeEquals(saved.getValidToDate(),
            new DateTime(2017, 9, 1, 1, 2, 3, DateTimeZone.UTC), "Valid to date");

    saved = savedList.get(1);
    assertEquals(saved.getCreatedDate(), now);
    assertEquals(saved.getKbTenantId(), tenantId);
    assertEquals(saved.getTaxZone(), "NZ");
    assertEquals(saved.getProductName(), "memory-use");
    assertEquals(saved.getTaxCode(), "GST");
    assertDateTimeEquals(saved.getValidFromDate(),
            new DateTime(2017, 9, 1, 1, 2, 3, DateTimeZone.UTC), "Valid from date");
    assertNull(saved.getValidToDate(), "Valid to date");
}
 
开发者ID:SolarNetwork,项目名称:killbill-easytax-plugin,代码行数:47,代码来源:EasyTaxServletTests.java

示例13: load

import com.google.common.io.Resources; //导入方法依赖的package包/类
private JsonElement load(String name, Class<? extends JsonElement> cls) throws IOException {

        URL url = Resources.getResource("json/PUBNUB_" + name + ".json");

        String json = new String(Resources.toByteArray(url));

        return gson.fromJson(json, cls);

    }
 
开发者ID:after-the-sunrise,项目名称:bitflyer4j,代码行数:10,代码来源:RealtimeServiceImplTest.java


注:本文中的com.google.common.io.Resources.toByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。