本文整理汇总了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();
}
}
示例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;
}
示例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);
}
}
示例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$
}
}