當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。