@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "input files are specified by admin, not unchecked user input") @Override public File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException { String baseName = srcFile.getName().getBaseName(); try { String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); File file = File.createTempFile("vfsr_", "_" + safeBasename, tempDir); file.deleteOnExit(); final FileObject destFile = context.toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } catch (IOException e) { throw new FileSystemException(e); } }
/** * Removes %nn encodings from a string. * * @param decodedStr The decoded String. * @return The encoded String. */ public static String encode(final String decodedStr) { return encode(decodedStr, null); }
/** * Removes %nn encodings from a string. * * @param decodedStr The decoded String. * @return The encoded String. */ public static String encode(final String decodedStr) { return encode(decodedStr, null); }
/** * Removes %nn encodings from a string. * @param decodedStr The decoded String. * @return The encoded String. */ public static String encode(final String decodedStr) { return encode(decodedStr, null); }
/** * Removes %nn encodings from a string. * * @param decodedStr The decoded String. * @return The encoded String. */ public static String encode(final String decodedStr) { return encode(decodedStr, null); }
/** * Returns the children of the file. */ @Override protected String[] doListChildren() throws Exception { return UriParser.encode(file.list()); }
/** * Returns the children of the file. */ @Override protected String[] doListChildren() throws Exception { return UriParser.encode(file.list()); }
/** * Returns the children of the file. */ @Override protected String[] doListChildren() throws Exception { return UriParser.encode(file.list()); }
/** * Returns the children of the file. */ @Override protected String[] doListChildren() throws Exception { return UriParser.encode(file.list()); }
/** * Encodes and appends a string to a StringBuilder. * * @param buffer The StringBuilder to append to. * @param unencodedValue The String to encode and append. * @param reserved characters to encode. */ public static void appendEncoded(final StringBuilder buffer, final String unencodedValue, final char[] reserved) { final int offset = buffer.length(); buffer.append(unencodedValue); encode(buffer, offset, unencodedValue.length(), reserved); }
/** * Encodes and appends a string to a StringBuilder. * * @param buffer The StringBuilder to append to. * @param unencodedValue The String to encode and append. * @param reserved characters to encode. */ public static void appendEncoded(final StringBuilder buffer, final String unencodedValue, final char[] reserved) { final int offset = buffer.length(); buffer.append(unencodedValue); encode(buffer, offset, unencodedValue.length(), reserved); }
/** * Encodes and appends a string to a StringBuilder. * * @param buffer The StringBuilder to append to. * @param unencodedValue The String to encode and append. * @param reserved characters to encode. */ public static void appendEncoded(final StringBuilder buffer, final String unencodedValue, final char[] reserved) { final int offset = buffer.length(); buffer.append(unencodedValue); encode(buffer, offset, unencodedValue.length(), reserved); }
/** * Encodes and appends a string to a StringBuilder. * @param buffer The StringBuilder to append to. * @param unencodedValue The String to encode and append. * @param reserved characters to encode. */ public static void appendEncoded(final StringBuilder buffer, final String unencodedValue, final char[] reserved) { final int offset = buffer.length(); buffer.append(unencodedValue); encode(buffer, offset, unencodedValue.length(), reserved); }
/** * Finds a local file. * * @param file The File to locate. * @return the located FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject findLocalFile(final File file) throws FileSystemException { return findLocalFile(UriParser.encode(file.getAbsolutePath())); // return findLocalFile(file.getAbsolutePath()); }
/** * Finds a local file. * * @param file The File to locate. * @return the located FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject findLocalFile(final File file) throws FileSystemException { return findLocalFile(UriParser.encode(file.getAbsolutePath())); // return findLocalFile(file.getAbsolutePath()); }
/** * Finds a local file. * * @param file The File to locate. * @return the located FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject findLocalFile(final File file) throws FileSystemException { return findLocalFile(UriParser.encode(file.getAbsolutePath())); // return findLocalFile(file.getAbsolutePath()); }
/** * Finds a local file. * @param file The File to locate. * @return the located FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject findLocalFile(final File file) throws FileSystemException { return findLocalFile(UriParser.encode(file.getAbsolutePath())); // return findLocalFile(file.getAbsolutePath()); }
/** * Create the temporary file name. * * @param baseName The base to prepend to the file name being created. * @return the name of the File. */ protected String createFilename(final String baseName) { // BUG29007 // return baseName + "_" + getFilecount() + ".tmp"; // imario@apache.org: BUG34976 get rid of maybe reserved and dangerous characters // e.g. to allow replication of http://hostname.org/fileservlet?file=abc.txt final String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); return "tmp_" + getFilecount() + "_" + safeBasename; }
/** * Lists the children of the file. Is only called if {@link #doGetType} returns {@link FileType#FOLDER}. */ @Override protected String[] doListChildren() throws Exception { // VFS-210: do not try to get listing for anything else than directories if (!file.isDirectory()) { return null; } return UriParser.encode(file.list()); }
@Override public File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException { String baseName = srcFile.getName().getBaseName(); try { String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); File file = File.createTempFile("vfsr_", "_" + safeBasename, tempDir); file.deleteOnExit(); final FileObject destFile = context.toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } catch (IOException e) { throw new FileSystemException(e); } }