當前位置: 首頁>>代碼示例>>Java>>正文


Java Resources.copy方法代碼示例

本文整理匯總了Java中com.google.common.io.Resources.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.copy方法的具體用法?Java Resources.copy怎麽用?Java Resources.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.io.Resources的用法示例。


在下文中一共展示了Resources.copy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeSelfReferencingJarFile

import com.google.common.io.Resources; //導入方法依賴的package包/類
private static void writeSelfReferencingJarFile(File jarFile, String... entries)
    throws IOException {
  Manifest manifest = new Manifest();
  // Without version, the manifest is silently ignored. Ugh!
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName());

  Closer closer = Closer.create();
  try {
    FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile));
    JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut));
    for (String entry : entries) {
      jarOut.putNextEntry(new ZipEntry(entry));
      Resources.copy(ClassPathTest.class.getResource(entry), jarOut);
      jarOut.closeEntry();
    }
  } catch (Throwable e) {
    throw closer.rethrow(e);
  } finally {
    closer.close();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:23,代碼來源:ClassPathTest.java

示例2: configureTestKeyStore

import com.google.common.io.Resources; //導入方法依賴的package包/類
public static Map<String, File> configureTestKeyStore(File baseDir, File keyStoreFile)
    throws IOException {
  Map<String, File> result = Maps.newHashMap();

  if (System.getProperty("java.vendor").contains("IBM")) {
    Resources.copy(Resources.getResource("ibm-test.keystore"),
        new FileOutputStream(keyStoreFile));
  } else {
    Resources.copy(Resources.getResource("sun-test.keystore"),
        new FileOutputStream(keyStoreFile));
  }

  /* Commands below:
   * keytool -genseckey -alias key-0 -keypass keyPassword -keyalg AES \
   *   -keysize 128 -validity 9000 -keystore src/test/resources/test.keystore \
   *   -storetype jceks -storepass keyStorePassword
   * keytool -genseckey -alias key-1 -keyalg AES -keysize 128 -validity 9000 \
   *   -keystore src/test/resources/test.keystore -storetype jceks \
   *   -storepass keyStorePassword
   */
  // key-0 has own password, key-1 used key store password
  result.put("key-0", TestUtils.writeStringToFile(baseDir, "key-0", "keyPassword"));
  result.put("key-1", null);
  return result;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:26,代碼來源:EncryptionTestUtils.java

示例3: copyTestFile

import com.google.common.io.Resources; //導入方法依賴的package包/類
public static File copyTestFile(String source, TemporaryFolder root, String target) {
    File targetFile = new File(root.getRoot(), target);
    targetFile.getParentFile().mkdirs();
    try (OutputStream stream = new FileOutputStream(targetFile)) {
        Resources.copy(WhoCalled.$.getCallingClass().getResource(source), stream);
        return targetFile;
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
開發者ID:palantir,項目名稱:gradle-circle-style,代碼行數:11,代碼來源:TestCommon.java

示例4: createLogback

import com.google.common.io.Resources; //導入方法依賴的package包/類
private void createLogback ( final Element comp, final EquinoxAppService eas, final File resourceBase ) throws Exception
{
    final Element file = createElement ( comp, "File" ); //$NON-NLS-1$
    final String serviceName = makeServiceName ( eas );
    file.setAttribute ( "Id", "logback.xml_" + serviceName ); //$NON-NLS-1$ //$NON-NLS-2$
    file.setAttribute ( "Source", String.format ( "resources\\apps\\%s\\logback.xml", eas.getName () ) ); //$NON-NLS-1$ //$NON-NLS-2$

    final File logback = new File ( resourceBase, "logback.xml" ); //$NON-NLS-1$
    try ( FileOutputStream out = new FileOutputStream ( logback ) )
    {
        Resources.copy ( Resources.getResource ( MsiHandler.class, "templates/msi/app.logback.xml" ), out ); //$NON-NLS-1$
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:14,代碼來源:WixDeploymentSetupBuilder.java


注:本文中的com.google.common.io.Resources.copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。