/** * Rename a file if this is allowed. This method is similar to Java 7 * <code>java.nio.file.Files.move</code>. * * @param source the old fully qualified file name * @param target the new fully qualified file name */ public static void move(String source, String target) { FilePath.get(source).moveTo(FilePath.get(target), false); }
/** * Check if the file is writable. * This method is similar to Java 7 * <code>java.nio.file.Path.checkAccess(AccessMode.WRITE)</code> * * @param fileName the file name * @return if the file is writable */ public static boolean canWrite(String fileName) { return FilePath.get(fileName).canWrite(); }
/** * Delete a file or directory if it exists. * Directories may only be deleted if they are empty. * This method is similar to Java 7 * <code>java.nio.file.Path.deleteIfExists</code>. * * @param path the file or directory name */ public static void delete(String path) { FilePath.get(path).delete(); }
/** * Create an input stream to read from the file. * This method is similar to Java 7 * <code>java.nio.file.Path.newInputStream</code>. * * @param fileName the file name * @return the input stream */ public static InputStream newInputStream(String fileName) throws IOException { return FilePath.get(fileName).newInputStream(); }
FilePath p = FilePath.get(fileName); !fileName.startsWith(p.getScheme() + ":")) { FilePath f = FilePath.get(fileName); FilePath parent = f.getParent(); if (parent != null && !parent.exists()) { throw DataUtils.newIllegalArgumentException( "Directory does not exist: {0}", parent); if (f.exists() && !f.canWrite()) { readOnly = true; file = f.open(readOnly ? "r" : "rw"); if (encryptionKey != null) { byte[] key = FilePathEncrypt.getPasswordBytes(encryptionKey);
/** * Create a new temporary file. * * @param suffix the suffix * @param deleteOnExit if the file should be deleted when the virtual * machine exists * @param inTempDir if the file should be stored in the temporary directory * @return the name of the created file */ @SuppressWarnings("unused") public FilePath createTempFile(String suffix, boolean deleteOnExit, boolean inTempDir) throws IOException { while (true) { FilePath p = getPath(name + getNextTempFileNamePart(false) + suffix); if (p.exists() || !p.createFile()) { // in theory, the random number could collide getNextTempFileNamePart(true); continue; } p.open("rw").close(); return p; } }
/** * Get the parent directory of a file or directory. This method returns null * if there is no parent. This method is similar to Java 7 * <code>java.nio.file.Path.getParent</code>. * * @param fileName the file or directory name * @return the parent directory name */ public static String getParent(String fileName) { FilePath p = FilePath.get(fileName).getParent(); return p == null ? null : p.toString(); }
/** * Open a random access file object. * This method is similar to Java 7 * <code>java.nio.channels.FileChannel.open</code>. * * @param fileName the file name * @param mode the access mode. Supported are r, rw, rws, rwd * @return the file object */ public static FileChannel open(String fileName, String mode) throws IOException { return FilePath.get(fileName).open(mode); }
long newestVersion = -1; PrintWriter pw = new PrintWriter(writer, true); if (!FilePath.get(fileName).exists()) { pw.println("File not found: " + fileName); return newestVersion; int blockSize = MVStore.BLOCK_SIZE; try { file = FilePath.get(fileName).open("r"); FilePath.get(fileName + ".temp").delete(); target = FilePath.get(fileName + ".temp").open("rw"); long fileSize = file.size(); ByteBuffer block = ByteBuffer.allocate(4096);
@Override public void connectionMade(final String name, final Connection connection) { final FilePath filePath = FilePath.get(resource); try (final InputStream inputStream = filePath.newInputStream(); final Statement statement = connection.createStatement(); final ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, inputStream.available())); ) { copyToOutputStream(inputStream, out); statement.execute(convertToString(out.toByteArray())); } catch (IOException e) { throw new IllegalArgumentException(String.format("Could not read SQL from file path \"%s\"", filePath.getName()), e); } catch (SQLException e) { throw new IllegalArgumentException(String.format("Could not run SQL script from file path \"%s\"", filePath.getName()), e); } }
/** * Unregister a file provider. * * @param provider the file provider */ public static void unregister(FilePath provider) { registerDefaultProviders(); providers.remove(provider.getScheme()); }
/** * Get the file or directory name (the last element of the path). * This method is similar to Java 7 <code>java.nio.file.Path.getName</code>. * * @param path the directory and file name * @return just the file name */ public static String getName(String path) { return FilePath.get(path).getName(); }
/** * Get the canonical file or directory name. This method is similar to Java * 7 <code>java.nio.file.Path.toRealPath</code>. * * @param fileName the file name * @return the normalized file name */ public static String toRealPath(String fileName) { return FilePath.get(fileName).toRealPath().toString(); }
@Override public InputStream newInputStream() throws IOException { InputStream input = getBase().newInputStream(); for (int i = 1;; i++) { FilePath f = getBase(i); if (f.exists()) { InputStream i2 = f.newInputStream(); input = new SequenceInputStream(input, i2); } else { break; } } return input; }
@Override public ArrayList<FilePath> newDirectoryStream() { List<FilePath> list = getBase().newDirectoryStream(); ArrayList<FilePath> newList = New.arrayList(); for (FilePath f : list) { if (!f.getName().endsWith(PART_SUFFIX)) { newList.add(wrap(f)); } } return newList; }