APISonar


com.google.common.io.Files.copy

> com > google > common > io > Files > copy
com APIs google APIs common APIs io APIs Files APIs copy APIs

Example 1
public static boolean copyRecursively(File src, File target)
    {
        if (src.isDirectory()) {
            return copyDirectoryContents(src, target);
        }
        else {
            try {
                Files.copy(src, target);
                return true;
            }
            catch (IOException e) {
                return false;
            }
        }
    }
Example 2
public void copy(File from, File targetDir) throws IOException {
        File target = targetDir.toPath().resolve(from.getName()).toFile();
        Files.copy(from, target);
        created.add(target);
    }
Example 3
File getTinyArpaFile() throws IOException {
    File tmp = File.createTempFile("tiny", ".arpa");
    Files.copy(new File(TINY_ARPA_URL.getFile()), tmp);
    return tmp;
  }
Example 4
private File copyToTmp(String file) throws IOException {
		File newFile = tmpDir.newFile();
		Files.copy(new File(TEST_FILE_LOCATION + file), newFile);
		return newFile;
	}
Example 5
private void ensureLib(String tempdir, String name, String resource) {
    try {
      File outFile = new File(tempdir, name);
      if (outFile.exists()) {
        return;
      }
      File tmpLibDir = new File(tempdir);
      tmpLibDir.mkdirs();
      Files.copy(Resources.newInputStreamSupplier(Compiler.class.getResource(resource)), outFile);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Example 6
private static void copyFileInJar(File inputDir, File inputFile, JarOutputStream jarOutputStream)
            throws IOException {

        String entryName = inputFile.getPath().substring(inputDir.getPath().length() + 1);
        JarEntry jarEntry = new JarEntry(entryName);
        jarOutputStream.putNextEntry(jarEntry);
        Files.copy(inputFile, jarOutputStream);
        jarOutputStream.closeEntry();
    }
Example 7
private static void writeBackupFile(File file) {
        File backupFile = new File(file.getParentFile(), file.getName() + ".invalid-orig");
        try {
            Files.copy(file, backupFile);
            logger.warn("due to an error in the config file, it has been backed up to extension"
                    + " '.invalid-orig' and will be overwritten with the default config");
        } catch (IOException f) {
            logger.warn("error making a copy of the invalid config file before overwriting it",
                    f);
        }
    }
Example 8
public void download(URI uri, File toFile) {
    try {
      Files.copy(downloader.newInputSupplier(uri, this.readTimeout), toFile);
    } catch (IOException e) {
      FileUtils.deleteQuietly(toFile);
      throw failToDownload(uri, e);
    }
  }
Example 9
private void copyFileToDest(String checkpointId, File file) throws IOException {
        String destPath = RocksUtils.getDestPath(dbPrefix, checkpointId, file);
        try (OutputStream os = checkpointStore.openOutputStream(destPath)) {
            Files.copy(file, os);
        }
    }
Example 10
private void dumpLogs(Step step) {
        File logFile = new File(compiler.logDir(), step.name() + ".log");
        try {
            print(">>>>>");
            Files.copy(logFile, System.out);
            print("<<<<<");
        } catch (IOException e) {
            print("Unable to dump log file %s", logFile.getName());
        }
    }
Example 11
public String uploadSeedFile(final serverSwitch sb, final File seedFile) throws Exception {

        String seedFilePath = "";
        try {
            seedFilePath = sb.getConfig(CONFIG_FILE_PATH,"");
            if (seedFilePath.isEmpty()) throw new Exception("Path to seed file is not configured properly");

            final File publicSeedFile = new File(seedFilePath);
            Files.copy(seedFile,publicSeedFile);

            return "Seed-List file stored successfully";
        } catch (final Exception e) {
            throw new Exception("Unable to store the seed-list file into the filesystem using path '" + seedFilePath + "'. " + e.getMessage());
        }
    }
Example 12
private static URL makeJarUrlWithName(String name) throws IOException {
    File fullPath = new File(Files.createTempDir(), name);
    File jarFile = JarFileFinder.pickAnyJarFile();
    Files.copy(jarFile, fullPath);
    return fullPath.toURI().toURL();
  }
Example 13
public static File genLocalJarForTest(String pathToClazzFile, String clazzName)
      throws IOException, InterruptedException {
    String u = pathToClazzFile;
    File dir = new File(u);
    File parentDir = dir.getParentFile();
    File f = new File(parentDir, clazzName + JAVA_FILE_EXT);
    Files.copy(dir, f);
    executeCmd(new String[] { "javac", clazzName + JAVA_FILE_EXT }, parentDir);
    executeCmd(new String[] { "jar", "cf", clazzName + JAR_FILE_EXT, clazzName + CLAZZ_FILE_EXT },
        parentDir);
    f.delete();
    new File(parentDir, clazzName + CLAZZ_FILE_EXT).delete();
    return new File(parentDir, clazzName + JAR_FILE_EXT);
  }
Example 14
public void testWithChecksums() throws Exception {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        URL fileUrl = cl.getResource("chronicle-map-3-12-with-checksums.dat");
        File file = new File(fileUrl.toURI());
        File persistenceFile = Builder.getPersistenceFile();
        Files.copy(file, persistenceFile);
        try (ChronicleMap<Integer, String> map = ChronicleMap.of(Integer.class, String.class)
                .averageValue("1")
                .entries(1)
                .recoverPersistedTo(persistenceFile, false)) {
            assertEquals(2, map.size());
            assertEquals("1", map.get(1));
            assertEquals("-1", map.get(-1));
        }
    }
Example 15
public synchronized void reconfigure(Properties properties) throws Exception {
    File configFile = createConfigurationFile(agentName, properties);
    Files.copy(configFile, new File(configFilePath));
    configFile.delete();
    LOGGER.info("Updated agent config file: " + configFilePath);
  }
Example 16
private static void printJavaLicenseFiles(OutErr outErr, Path bundledJdkOrJre) {
    try {
      for (Path path : bundledJdkOrJre.getDirectoryEntries()) {
        if (JAVA_LICENSE_FILES.contains(path.getBaseName().toLowerCase())) {
          outErr.printOutLn(path.getPathString() + ":\n");
          Files.copy(path.getPathFile(), outErr.getOutputStream());
          outErr.printOutLn("\n");
        }
      }
    } catch (IOException e) {
      throw new IllegalStateException(
          "I/O error while trying to print license file of bundled JDK or JRE: " + e.getMessage(),
          e);
    }
  }
Example 17
public void crunchPng(File from, File to)
      throws InterruptedException, LoggedErrorException, IOException {
    if (from.getPath().endsWith(SdkConstants.DOT_9PNG)) {
      super.crunchPng(from, to);
    } else {
      Files.copy(from, to);
    }
  }
Example 18
public void injectIcon(int id, final InputStream iconStream) throws IOException {
    File f = File.createTempFile("launcher", "ico");
    Files.copy(new InputSupplier<InputStream>() {
      @Override
      public InputStream getInput() throws IOException {
        return iconStream;
      }
    }, f);
    IconResourceInjector iconInjector = new IconResourceInjector();
    iconInjector.injectIcon(f, myRoot, "IRD" + id);
  }
Example 19
public void whenCopyFileUsingFiles_thenCopied() throws IOException {
        final String expectedValue = "Hello world";

        final File file1 = new File("src/test/resources/test1.in");
        final File file2 = new File("src/test/resources/test_copy.in");

        Files.copy(file1, file2);
        final String result = Files.toString(file2, Charsets.UTF_8);

        assertEquals(expectedValue, result);
    }
Example 20
public void pushTaskLog(final String taskid, File file) throws IOException
  {
    if (config.getDirectory().exists() || config.getDirectory().mkdirs()) {
      final File outputFile = fileForTask(taskid);
      Files.copy(file, outputFile);
      log.info("Wrote task log to: %s", outputFile);
    } else {
      throw new IOE("Unable to create task log dir[%s]", config.getDirectory());
    }
  }
Example 21
public static File readResourceToTempFile(String resourceName) throws IOException {
    InputSupplier<? extends InputStream> inSupplier;
    try {
      URL resourceURL = Resources.getResource(GroupLensRecommender.class, resourceName);
      inSupplier = Resources.newInputStreamSupplier(resourceURL);
    } catch (IllegalArgumentException iae) {
      File resourceFile = new File("src/main/java" + resourceName);
      inSupplier = Files.newInputStreamSupplier(resourceFile);
    }
    File tempFile = File.createTempFile("taste", null);
    tempFile.deleteOnExit();
    Files.copy(inSupplier, tempFile);
    return tempFile;
  }
Example 22
private void put(File fromFile, String toBlobPath) throws IOException {
		try (OutputStream os = fileSystem.create(new Path(toBlobPath), FileSystem.WriteMode.OVERWRITE)) {
			LOG.debug("Copying from {} to {}.", fromFile, toBlobPath);
			Files.copy(fromFile, os);
		}
	}
Example 23
private static boolean changeSkin(final Switchboard sb, final String skinPath, final String skin) {
        final File htdocsDir = new File(sb.getDataPath("htDocsPath", "DATA/HTDOCS"), "env");
        final File styleFile = new File(htdocsDir, "style.css");
        final File skinFile = new File(skinPath, skin);

        styleFile.getParentFile().mkdirs();
        try {
            Files.copy(skinFile, styleFile);
            sb.setConfig("currentSkin", skin.substring(0, skin.length() - 4));
            return true;
        } catch (final IOException e) {
            return false;
        }
    }
Example 24
private void copyFirefoxDriverDefaultsToOutputDir() throws IOException {
    File defaults = InProject.locate("javascript/firefox-driver/webdriver.json");
    File out = InProject.locate("java/client/build/production/org/openqa/selenium/firefox/FirefoxProfile.class").getParentFile();
    out = new File(out, "webdriver.json");
    Files.copy(defaults, out);
  }
Example 25
public void testLoadCatalogFromExternalFile() throws CatalogApiException, IOException, URISyntaxException {
        final File originFile = new File(Resources.getResource("SpyCarBasic.xml").toURI());
        final File destinationFile = new File(Files.createTempDir().toString() + "/SpyCarBasicRelocated.xml");
        destinationFile.deleteOnExit();
        Files.copy(originFile, destinationFile);
        final VersionedCatalog c = loader.loadDefaultCatalog(destinationFile.toURI().toString());
        Assert.assertEquals(c.getCatalogName(), "SpyCarBasic");
    }