本文整理汇总了Java中com.google.common.io.Files.copy方法的典型用法代码示例。如果您正苦于以下问题:Java Files.copy方法的具体用法?Java Files.copy怎么用?Java Files.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Files
的用法示例。
在下文中一共展示了Files.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: migrate
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Migrates the config to a new config version.
*
* @param configFile the file to migrate
* @param config the config to migrate
* @throws ConfigException if there was an error while creating an backup
*/
public void migrate(@Nonnull File configFile, @Nonnull Config config) {
log.info("Migrating config from v" + config.getCurrentVersion() + " to v" + config
.getConfigVersion());
try {
File backup = new File(configFile.getParent(),
configFile.getName() + ".v" + config.getCurrentVersion() + ".backup");
Files.copy(configFile, backup);
log.info("Saved backup to " + backup.getAbsolutePath());
} catch (IOException e) {
throw new ConfigException("Error while migrating config", e);
}
config.setCurrentVersion(config.getConfigVersion());
saveConfig(configFile, config);
log.info("Done migrating");
}
示例2: extractProjectFiles
import com.google.common.io.Files; //导入方法依赖的package包/类
private ArrayList<String> extractProjectFiles(ZipFile inputZip, File projectRoot)
throws IOException {
ArrayList<String> projectFileNames = Lists.newArrayList();
Enumeration<? extends ZipEntry> inputZipEnumeration = inputZip.entries();
while (inputZipEnumeration.hasMoreElements()) {
ZipEntry zipEntry = inputZipEnumeration.nextElement();
final InputStream extractedInputStream = inputZip.getInputStream(zipEntry);
File extractedFile = new File(projectRoot, zipEntry.getName());
LOG.info("extracting " + extractedFile.getAbsolutePath() + " from input zip");
Files.createParentDirs(extractedFile); // Do I need this?
Files.copy(
new InputSupplier<InputStream>() {
public InputStream getInput() throws IOException {
return extractedInputStream;
}
},
extractedFile);
projectFileNames.add(extractedFile.getPath());
}
return projectFileNames;
}
示例3: testCalculateCrc
import com.google.common.io.Files; //导入方法依赖的package包/类
@Test
public void testCalculateCrc() throws Exception {
final File workingFile = new File("target/testCalculateCrc.log");
Files.copy(new File("src/test/resources/example-log-dir-hello/hello-0/00000000000000000000.log"), workingFile);
final SegmentFileUpdater verifier1 = new SegmentFileUpdater(workingFile, true);
// first verify integrity of original file
verifier1.run(null);
final SegmentFileUpdater updater = new SegmentFileUpdater(workingFile, true);
updater.run(new DestroyValueRecordUpdater('!'));
// re-run verification
final SegmentFileUpdater verifier2 = new SegmentFileUpdater(workingFile, true);
verifier2.run(new RecordUpdater() {
@Override
public boolean update(long offset, byte[] key, byte[] value) {
assertEquals('!', value[0]);
return false;
}
});
}
示例4: setUp
import com.google.common.io.Files; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
baseDir = Files.createTempDir();
configFile = new File(baseDir, TESTFILE.getName());
Files.copy(TESTFILE, configFile);
eventBus = new EventBus("test");
provider =
new PollingPropertiesFileConfigurationProvider("host1",
configFile, eventBus, 1);
provider.start();
LifecycleController.waitForOneOf(provider, LifecycleState.START_OR_ERROR);
}
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:16,代码来源:TestPollingPropertiesFileConfigurationProvider.java
示例5: saveImage
import com.google.common.io.Files; //导入方法依赖的package包/类
@TgRequest
public void saveImage(TgPhotos photos) {
PhotoSize largest = photos.get(photos.size() - 1);
File tmpFile = fileService.download(largest);
TgContext tgContext = TgContextHolder.currentContext();
String dirName = String.format("./%d_%s", tgContext.getUser().getId(), tgContext.getUser().getUserName());
File dir = new File(dirName);
if (!dir.exists())
if (!dir.mkdirs())
throw new IllegalStateException("Could not create directory");
File file = new File(dir, tmpFile.getName());
try {
Files.copy(tmpFile, file);
messageService.sendMessage("File saved!");
} catch (IOException e) {
messageService.sendMessage("Failed to save file!");
throw new IllegalStateException(e);
}
}
示例6: getImageFileMD5IgnoringTxId
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Calculate the md5sum of an image after zeroing out the transaction ID
* field in the header. This is useful for tests that want to verify
* that two checkpoints have identical namespaces.
*/
public static String getImageFileMD5IgnoringTxId(File imageFile)
throws IOException {
File tmpFile = File.createTempFile("hadoop_imagefile_tmp", "fsimage");
tmpFile.deleteOnExit();
try {
Files.copy(imageFile, tmpFile);
RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
try {
raf.seek(IMAGE_TXID_POS);
raf.writeLong(0);
} finally {
IOUtils.closeStream(raf);
}
return getFileMD5(tmpFile);
} finally {
tmpFile.delete();
}
}
示例7: zip
import com.google.common.io.Files; //导入方法依赖的package包/类
public static void zip(File directory, File zipfile) throws IOException
{
URI base = directory.toURI();
Deque<File> queue = new LinkedList<File>();
queue.push(directory);
OutputStream out = new FileOutputStream(zipfile);
Closeable res = null;
try
{
ZipOutputStream zout = new ZipOutputStream(out);
res = zout;
while (!queue.isEmpty())
{
directory = queue.pop();
for (File kid : directory.listFiles())
{
String name = base.relativize(kid.toURI()).getPath();
if (kid.isDirectory())
{
queue.push(kid);
name = name.endsWith("/") ? name : name + "/";
zout.putNextEntry(new ZipEntry(name));
} else
{
zout.putNextEntry(new ZipEntry(name));
Files.copy(kid, zout);
zout.closeEntry();
}
}
}
} finally
{
res.close();
}
}
示例8: copyMetadata
import com.google.common.io.Files; //导入方法依赖的package包/类
private void copyMetadata(File source, File dest) {
if (dest.mkdir()) {
for (File src : source.listFiles()) {
try {
Files.copy(src, new File(dest, src.getName()));
} catch (IOException ex) {
throw UncheckedException.throwAsUncheckedException(ex);
}
}
}
}
示例9: run
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Main method. Performs the evaluation in current thread.
*
* @param isResume Whether should resume interrupted evaluation.
*/
public void run(boolean isResume) {
boolean done = serverRunner.getTasks().isEmpty();
while (!done) {
File taskFile = serverRunner.getFreeTask();
IEvaluationTask task = EvaluationTaskFactory.build(taskFile);
if (task == null) {
break;
} else {
task.setResultBasePath(ServerRunner.getStatsBasePath());
File taskDefFile = new File(task.getResultPath(), taskFile.getName());
try {
taskDefFile.delete();
Files.copy(taskFile, taskDefFile);
} catch (IOException ex) {
//TODO: Add logging
//Logger.getLogger(DirectRunner.class.getName()).log(Level.SEVERE, null, ex);
}
SingleNavigationTaskEvaluator evaluator = new SingleNavigationTaskEvaluator();
int result = evaluator.execute(task, isResume, label);
if (result == 0) {
serverRunner.getTasks().remove(taskFile);
}
}
done = serverRunner.getTasks().isEmpty();
}
}
示例10: attachCompAssets
import com.google.common.io.Files; //导入方法依赖的package包/类
private boolean attachCompAssets() {
createDir(project.getAssetsDirectory()); // Needed to insert resources.
try {
// Gather non-library assets to be added to apk's Asset directory.
// The assets directory have been created before this.
File compAssetDir = createDir(project.getAssetsDirectory(),
ASSET_DIRECTORY);
for (String type : assetsNeeded.keySet()) {
for (String assetName : assetsNeeded.get(type)) {
File targetDir = compAssetDir;
String sourcePath = "";
String pathSuffix = RUNTIME_FILES_DIR + assetName;
if (simpleCompTypes.contains(type)) {
sourcePath = getResource(pathSuffix);
} else if (extCompTypes.contains(type)) {
sourcePath = getExtCompDirPath(type) + pathSuffix;
targetDir = createDir(targetDir, EXT_COMPS_DIR_NAME);
targetDir = createDir(targetDir, type);
} else {
userErrors.print(String.format(ERROR_IN_STAGE, "Assets"));
return false;
}
Files.copy(new File(sourcePath), new File(targetDir, assetName));
}
}
return true;
} catch (IOException e) {
e.printStackTrace();
userErrors.print(String.format(ERROR_IN_STAGE, "Assets"));
return false;
}
}
示例11: init
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Initialize Tomcat inner datasets.
*/
public void init () throws TomcatException
{
tomcatpath = configurationManager.getTomcatConfiguration ().getPath ();
final String extractDirectory = tomcatpath;
File extractDirectoryFile = new File (extractDirectory);
LOGGER.info("Starting tomcat in " + extractDirectoryFile.getPath());
try
{
extract (extractDirectoryFile, extractDirectory);
// create tomcat various paths
new File (extractDirectory, "conf").mkdirs ();
File cfg =
new File (ClassLoader.getSystemResource ("server.xml").toURI ());
Files.copy (cfg, new File (extractDirectory, "conf/server.xml"));
new File (extractDirectory, "logs").mkdirs ();
new File (extractDirectory, "webapps").mkdirs ();
new File (extractDirectory, "work").mkdirs ();
File tmpDir = new File (extractDirectory, "temp");
tmpDir.mkdirs ();
System.setProperty ("java.io.tmpdir", tmpDir.getAbsolutePath ());
System.setProperty ("catalina.base",
extractDirectoryFile.getAbsolutePath ());
System.setProperty ("catalina.home",
extractDirectoryFile.getAbsolutePath ());
cat = new Catalina ();
}
catch (Exception e)
{
throw new TomcatException ("Cannot initalize Tomcat environment.", e);
}
Runtime.getRuntime ().addShutdownHook (new TomcatShutdownHook ());
}
示例12: copyFolder
import com.google.common.io.Files; //导入方法依赖的package包/类
protected void copyFolder (File from, File to) throws IOException
{
to.mkdirs ();
for (File cfg : from.listFiles ())
{
if (cfg.isDirectory ())
{
copyFolder (cfg, new File (to, cfg.getName ()));
}
else
{
Files.copy (cfg, new File (to, cfg.getName ()));
}
}
}
示例13: copyFile
import com.google.common.io.Files; //导入方法依赖的package包/类
private void copyFile(String name, File to)
{
File parentFile = parent.getMapFileFromName(name);
if (parentFile.exists())
{
try
{
Files.copy(parentFile, to);
}
catch (IOException e)
{
FMLLog.log(Level.ERROR, e, "A critical error occurred copying %s to world specific dat folder - new file will be created.", parentFile.getName());
}
}
}
示例14: configure
import com.google.common.io.Files; //导入方法依赖的package包/类
@Override
public void configure(String configDirectory){
File sourceFile = new File(sourceFileLocation);
File destinationFile = new File(configDirectory + "/" + destinationFileName);
if(destinationFile.exists()){
logger.warn("replacing {} with {}", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
}else{
logger.warn("creating {} from {}", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
}
try{
Files.copy(sourceFile, destinationFile);
}catch(IOException e){
throw new RuntimeException(e);
}
}
示例15: getResource
import com.google.common.io.Files; //导入方法依赖的package包/类
/**
* Writes out the given resource as a temp file and returns the absolute path.
* Caches the location of the files, so we can reuse them.
*
* @param resourcePath the name of the resource
*/
static synchronized String getResource(String resourcePath) {
try {
File file = resources.get(resourcePath);
if (file == null) {
String basename = PathUtil.basename(resourcePath);
String prefix;
String suffix;
int lastDot = basename.lastIndexOf(".");
if (lastDot != -1) {
prefix = basename.substring(0, lastDot);
suffix = basename.substring(lastDot);
} else {
prefix = basename;
suffix = "";
}
while (prefix.length() < 3) {
prefix = prefix + "_";
}
file = File.createTempFile(prefix, suffix);
file.setExecutable(true);
file.deleteOnExit();
file.getParentFile().mkdirs();
Files.copy(Resources.newInputStreamSupplier(Compiler.class.getResource(resourcePath)),
file);
resources.put(resourcePath, file);
}
return file.getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}