private void uploadFile(String relPath, Path fullPath) throws DropboxException, IOException { if (!fullPath.toFile().exists()) return; /*if(api.metadata(relPath, 1, null, false, null).rev == MetaHandler.getRev(relPath)){ logger.debug("File "+relPath+" not changed"); return; }*/ VOSync.debug("Uploading " + relPath); String rev = MetaHandler.getRev(relPath); InputStream inp = new FileInputStream(fullPath.toFile()); Entry fileEntry = api.putFile(relPath, inp, fullPath.toFile().length(), rev, null); inp.close(); Path destFilePath = FileSystems.getDefault() .getPath(fullPath.toFile().getParentFile().getPath(), fileEntry.fileName()); MetaHandler.setFile(relPath, destFilePath.toFile(), fileEntry.rev); logger.debug(relPath + " put to db"); // if the file was renamed, move the file on disk and download the current from server if (!fileEntry.fileName().equals(fullPath.toFile().getName())) { logger.error(fileEntry.fileName() + " != " + fullPath.toFile().getName()); fullPath.toFile().renameTo(destFilePath.toFile()); } }
/** * Recursively rebuild the tree nodes. * * @param root The full abstract path to the root saved layout directory. * @param local The current directory relative to root (null if none). * @param tnode The current parent tree node. */ private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) { TreeSet<Path> subdirs = new TreeSet<Path>(); TreeSet<String> layouts = new TreeSet<String>(); { Path current = new Path(root, local); File files[] = current.toFile().listFiles(); if (files != null) { int wk; for (wk = 0; wk < files.length; wk++) { String name = files[wk].getName(); if (files[wk].isDirectory()) subdirs.add(new Path(local, name)); else if (files[wk].isFile()) layouts.add(name); } } } for (Path subdir : subdirs) { TreeData data = new TreeData(subdir); DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true); tnode.add(child); rebuildTreeModel(root, subdir, child); } for (String lname : layouts) { TreeData data = new TreeData(new Path(local, lname), lname); DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false); tnode.add(child); } }
private List<Path> getPathsFromFile(String file, List<Path> filesToCombine) throws IOException { Path filePath = Paths.get(file); File fileLister = filePath.toFile(); BufferedReader br = new BufferedReader(new FileReader(fileLister)); String line; PathMatcher matcher; Finder finder = new Finder(); String parentFolder; Path filePathToCombine; while ((line = br.readLine()) != null) { if (line.isEmpty()) { continue; } parentFolder = ""; filePathToCombine = Paths.get(line); if (filePathToCombine.getParent() != null) { parentFolder = filePathToCombine.getParent().toString(); } matcher = FileSystems.getDefault() .getPathMatcher("glob:" + filePathToCombine.getFileName().toString()); finder.setMatcher(matcher); Files.walkFileTree( Paths.get(fileLister.getAbsoluteFile().getParent() + parentFolder), finder); } filesToCombine.addAll(finder.getMatchPath()); return filesToCombine; }
public void testKryoSerializationRoundtrip() throws IOException { Path testDir = Files.createTempDirectory("test"); try { SliceManager sliceManager = new SliceManager(new KryoSliceSerializer(), new FileStorageManager(testDir)); doSerializationRoundtrip("kryo", sliceManager); } finally { FileHelper.delete(testDir.toFile()); } }
public Path dateiAuswählen(Path neuesLaufwerk) { JFileChooser fc1 = new JFileChooser(); fc1.setDialogTitle("SyncOrdner auswählen"); fc1.setCurrentDirectory(neuesLaufwerk.toFile()); fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return fc1.getSelectedFile().toPath(); else return null; }
public static long checksumRandomAccessFile(Path filename) throws IOException { try (RandomAccessFile file = new RandomAccessFile(filename.toFile(), "r")) { long length = file.length(); CRC32 crc = new CRC32(); for (long p = 0; p < length; p++) { file.seek(p); int c = file.readByte(); crc.update(c); } return crc.getValue(); } }
public void downloadFile(String relPath) { VOSync.debug("Downloading file from storage: " + relPath); Path filePath = FileSystems.getDefault().getPath(startDir.toString(), relPath.substring(1)); try { WatchKey key = filePath.getParent().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); keys.remove(key); key.cancel(); FileOutputStream outp = new FileOutputStream(filePath.toFile()); DropboxFileInfo info = api.getFile(relPath, null, outp, null); outp.close(); key = filePath.getParent().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); keys.put(key, filePath.getParent()); MetaHandler.setFile(relPath, filePath.toFile(), info.getMetadata().rev); } catch (IOException ex) { logger.error("Error downloading file " + relPath + ": " + ex.getMessage()); } catch (DropboxException ex) { ex.printStackTrace(); logger.error("Error downloading file " + relPath + ": " + ex.getMessage()); } }
static void testCopyInputStreamToFile(int size) throws IOException { Path tmpdir = createTempDirectory("blah"); Path source = tmpdir.resolve("source"); Path target = tmpdir.resolve("target"); try { boolean testReplaceExisting = rand.nextBoolean(); // create source file byte[] b = new byte[size]; rand.nextBytes(b); write(source, b); // target file might already exist if (testReplaceExisting && rand.nextBoolean()) { write(target, new byte[rand.nextInt(512)]); } // copy from stream to file InputStream in = new FileInputStream(source.toFile()); try { long n; if (testReplaceExisting) { n = copy(in, target, StandardCopyOption.REPLACE_EXISTING); } else { n = copy(in, target); } assertTrue(in.read() == -1); // EOF assertTrue(n == size); assertTrue(size(target) == size); } finally { in.close(); } // check file byte[] read = readAllBytes(target); assertTrue(Arrays.equals(read, b)); } finally { deleteIfExists(source); deleteIfExists(target); delete(tmpdir); } }
/** * Compresses the specified directory to a zip file * * @param dir the directory to compress * @return the compressed file * @throws IOException */ public static Path compress(Path dir) throws IOException { Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath()); Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath()); Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP); try (final ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(result.toFile())))) { // out.setMethod(ZipOutputStream.DEFLATED); final byte data[] = new byte[BUFFER]; // get a list of files from current directory Files.walkFileTree( dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException { final File file = path.toFile(); // compress to relative directory, not absolute final String root = StringUtils.substringAfter(file.getParent(), dir.toString()); try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file), BUFFER)) { final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName()); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } } return FileVisitResult.CONTINUE; } }); } return result; }
/** * Updates the asset references for a shot within Maya and then in pipeline. * * @param shotName The name of the shot being processed. * @param pRemoveRef The list of assets being dereferenced from the shot. * @param pReplaceRef The list of assets being referenced into the shot. * @param nameMap */ private void editShotReferences( String shotName, NodeMod targetMod, TreeSet<String> pRemoveRef, TreeSet<String> pReplaceRef, TreeMap<String, String> nameMap) throws PipelineException { logLine("Editing shot: " + shotName); boolean anim = !shotName.matches(lgtPattern); /* writing the mel script */ if (anim) { File script = null; try { script = File.createTempFile("UpdateAssetGUI.", ".mel", PackageInfo.sTempPath.toFile()); FileCleaner.add(script); } // end try catch (IOException ex) { throw new PipelineException( "Unable to create the temporary MEL script used to collect " + "texture information from the Maya scene!"); } // end catch try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(script))); for (String asset : pReplaceRef) { String nameSpace; if (asset.endsWith(lr)) nameSpace = nameMap.get(getShortName(asset.substring(0, asset.length() - 3))); else { System.err.println("This should not be happening, a hi res asset in a lo-res node."); continue; // nameSpace = nameMap.get(getShortName(asset)); } out.println("print (\"referencing file: $WORKING" + asset + ".ma\");"); out.println( "file -reference -namespace \"" + nameSpace + "\" \"$WORKING" + asset + ".ma\";"); } // end for for (String asset : pRemoveRef) { out.println("print (\"dereferencing file: $WORKING" + asset + ".ma\");"); out.println("file -rr \"$WORKING" + asset + ".ma\";"); } // end for out.println("// SAVE"); out.println("file -save;"); out.close(); } // end try catch (IOException ex) { throw new PipelineException( "Unable to write the temporary MEL script(" + script + ") used add the references!"); } // end catch NodeID targetID = new NodeID(w.user, w.view, shotName); // NodeStatus targetStat = mclient.status(targetID); /* run Maya to collect the information */ try { Path targetPath = getNodePath(shotName); ArrayList<String> args = new ArrayList<String>(); args.add("-batch"); args.add("-script"); args.add(script.getPath()); args.add("-file"); args.add(targetPath.toOsString()); Path wdir = new Path(PackageInfo.sProdPath.toOsString() + targetID.getWorkingParent()); TreeMap<String, String> env = mclient.getToolsetEnvironment( w.user, w.view, targetMod.getToolset(), PackageInfo.sOsType); Map<String, String> nenv = env; String midefs = env.get("PIPELINE_MI_SHADER_PATH"); if (midefs != null) { nenv = new TreeMap<String, String>(env); Path dpath = new Path(new Path(wdir, midefs)); nenv.put("MI_CUSTOM_SHADER_PATH", dpath.toOsString()); } String command = "maya"; if (PackageInfo.sOsType.equals(OsType.Windows)) command += ".exe"; SubProcessLight proc = new SubProcessLight("UpdateAssetGUI", command, args, env, wdir.toFile()); try { proc.start(); proc.join(); if (!proc.wasSuccessful()) { throw new PipelineException( "Did not correctly edit the reference due to a maya error.!\n\n" + proc.getStdOut() + "\n\n" + proc.getStdErr()); } // end if } // end try catch (InterruptedException ex) { throw new PipelineException(ex); } // end catch } // end try catch (Exception ex) { throw new PipelineException(ex); } // end catch } /*-edit the references in pipeline once they are done in the file-*/ BaseAction targetAction = targetMod.getAction(); for (String asset : pReplaceRef) { mclient.link( w.user, w.view, shotName, asset, LinkPolicy.Reference, LinkRelationship.All, null); if (anim) { /*Set the namespaces*/ String nameSpace = nameMap.get(getShortName(asset.substring(0, asset.length() - 3))); System.err.println(nameSpace); targetAction.initSourceParams(asset); targetAction.setSourceParamValue(asset, "PrefixName", nameSpace); targetMod.setAction(targetAction); } } w.mclient.modifyProperties(w.user, w.view, targetMod); for (String asset : pRemoveRef) mclient.unlink(w.user, w.view, shotName, asset); if (!anim) { System.err.println("Queuing the switchLgt node " + shotName); mclient.submitJobs(w.user, w.view, shotName, null); } } // end editShotReferences
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (_pathMatcher.matches(file.getFileName())) storeFile(file.toFile()); return super.visitFile(file, attrs); }