Author: ggregory
Date: Thu Sep 14 19:43:40 2017
New Revision: 1808388
URL: http://svn.apache.org/viewvc?rev=1808388&view=rev
Log:
Format to use { on the same line.
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ChangeLastModificationTime.java
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ShowProperties.java
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/FtpCheck.java
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/SftpCheck.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeAttributesMap.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileObject.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileProvider.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileSystem.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileName.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileNameParser.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileProvider.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileRandomAccessContent.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileSystem.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/util/FileObjectDataSource.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/util/RACRandomAccessFile.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/util/SharedRandomContentInputStream.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/test/java/org/apache/commons/vfs2/provider/smb/test/FileNameTestCase.java
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/test/java/org/apache/commons/vfs2/provider/smb/test/SmbProviderTestCase.java
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestCase.java
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ChangeLastModificationTime.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ChangeLastModificationTime.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ChangeLastModificationTime.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ChangeLastModificationTime.java
Thu Sep 14 19:43:40 2017
@@ -22,17 +22,13 @@ import org.apache.commons.vfs2.VFS;
/**
* Example to change the last modification time of the given file.
*/
-public final class ChangeLastModificationTime
-{
- private ChangeLastModificationTime()
- {
+public final class ChangeLastModificationTime {
+ private ChangeLastModificationTime() {
/* main class not instantiated. */
}
- public static void main(final String[] args) throws Exception
- {
- if (args.length == 0)
- {
+ public static void main(final String[] args) throws Exception {
+ if (args.length == 0) {
System.err.println("Please pass the name of a file as parameter.");
return;
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
Thu Sep 14 19:43:40 2017
@@ -42,62 +42,46 @@ import org.apache.commons.vfs2.operation
/**
* A simple command-line shell for performing file operations.
* <p>
- * See
- * <a href="https://wiki.apache.org/commons/VfsExampleShell">Commons VFS Shell
Examples</a>
- * in Apache Commons Wiki.
+ * See <a href="https://wiki.apache.org/commons/VfsExampleShell">Commons VFS
Shell Examples</a> in Apache Commons Wiki.
*/
-public final class Shell
-{
+public final class Shell {
private final FileSystemManager mgr;
private FileObject cwd;
private final BufferedReader reader;
- private Shell() throws IOException
- {
+ private Shell() throws IOException {
mgr = VFS.getManager();
cwd = mgr.toFileObject(new File(System.getProperty("user.dir")));
reader = new BufferedReader(new InputStreamReader(System.in,
Charset.defaultCharset()));
}
- public static void main(final String[] args)
- {
- try
- {
+ public static void main(final String[] args) {
+ try {
new Shell().go();
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
- private void go() throws Exception
- {
+ private void go() throws Exception {
System.out.println("VFS Shell " + getVersion(Shell.class));
- while (true)
- {
+ while (true) {
final String[] cmd = nextCommand();
- if (cmd == null)
- {
+ if (cmd == null) {
return;
}
- if (cmd.length == 0)
- {
+ if (cmd.length == 0) {
continue;
}
final String cmdName = cmd[0];
- if (cmdName.equalsIgnoreCase("exit") ||
cmdName.equalsIgnoreCase("quit"))
- {
+ if (cmdName.equalsIgnoreCase("exit") ||
cmdName.equalsIgnoreCase("quit")) {
return;
}
- try
- {
+ try {
handleCommand(cmd);
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
System.err.println("Command failed:");
e.printStackTrace(System.err);
}
@@ -107,113 +91,77 @@ public final class Shell
/**
* Handles a command.
*/
- private void handleCommand(final String[] cmd) throws Exception
- {
+ private void handleCommand(final String[] cmd) throws Exception {
final String cmdName = cmd[0];
- if (cmdName.equalsIgnoreCase("cat"))
- {
+ if (cmdName.equalsIgnoreCase("cat")) {
cat(cmd);
- }
- else if (cmdName.equalsIgnoreCase("cd"))
- {
+ } else if (cmdName.equalsIgnoreCase("cd")) {
cd(cmd);
- }
- else if (cmdName.equalsIgnoreCase("cp"))
- {
+ } else if (cmdName.equalsIgnoreCase("cp")) {
cp(cmd);
- }
- else if (cmdName.equalsIgnoreCase("help") || cmdName.equals("?"))
- {
+ } else if (cmdName.equalsIgnoreCase("help") || cmdName.equals("?")) {
help();
- }
- else if (cmdName.equalsIgnoreCase("ls"))
- {
+ } else if (cmdName.equalsIgnoreCase("ls")) {
ls(cmd);
- }
- else if (cmdName.equalsIgnoreCase("pwd"))
- {
+ } else if (cmdName.equalsIgnoreCase("pwd")) {
pwd();
- }
- else if (cmdName.equalsIgnoreCase("rm"))
- {
+ } else if (cmdName.equalsIgnoreCase("rm")) {
rm(cmd);
- }
- else if (cmdName.equalsIgnoreCase("touch"))
- {
+ } else if (cmdName.equalsIgnoreCase("touch")) {
touch(cmd);
- }
- else if (cmdName.equalsIgnoreCase("info"))
- {
+ } else if (cmdName.equalsIgnoreCase("info")) {
info(cmd);
- }
- else
- {
+ } else {
System.err.println("Unknown command \"" + cmdName + "\" (Try
'help').");
}
}
- private void info(String[] cmd) throws Exception
- {
- if (cmd.length > 1)
- {
+ private void info(String[] cmd) throws Exception {
+ if (cmd.length > 1) {
info(cmd[1]);
- }
- else
- {
- System.out.println("Default manager: \"" +
mgr.getClass().getName() + "\" " +
- "version " + getVersion(mgr.getClass()));
+ } else {
+ System.out.println(
+ "Default manager: \"" + mgr.getClass().getName() + "\" " +
"version " + getVersion(mgr.getClass()));
String[] schemes = mgr.getSchemes();
List<String> virtual = new ArrayList<>();
List<String> physical = new ArrayList<>();
- for (int i = 0; i < schemes.length; i++)
- {
+ for (int i = 0; i < schemes.length; i++) {
Collection<Capability> caps =
mgr.getProviderCapabilities(schemes[i]);
- if (caps != null)
- {
- if (caps.contains(Capability.VIRTUAL) ||
- caps.contains(Capability.COMPRESS) ||
- caps.contains(Capability.DISPATCHER))
- {
+ if (caps != null) {
+ if (caps.contains(Capability.VIRTUAL) ||
caps.contains(Capability.COMPRESS)
+ || caps.contains(Capability.DISPATCHER)) {
virtual.add(schemes[i]);
- }
- else
- {
+ } else {
physical.add(schemes[i]);
}
}
}
- if (!physical.isEmpty())
- {
+ if (!physical.isEmpty()) {
System.out.println(" Provider Schemes: " + physical);
}
- if (!virtual.isEmpty())
- {
+ if (!virtual.isEmpty()) {
System.out.println(" Virtual Schemes: " + virtual);
}
- }
+ }
}
- private void info(String scheme) throws Exception
- {
- System.out.println("Provider Info for scheme \"" + scheme + "\":");
- Collection<Capability> caps;
- caps = mgr.getProviderCapabilities(scheme);
- if (caps != null && !caps.isEmpty())
- {
- System.out.println(" capabilities: " + caps);
- }
- FileOperationProvider[] ops = mgr.getOperationProviders(scheme);
- if (ops != null && ops.length > 0)
- {
- System.out.println(" operations: " + ops);
- }
+ private void info(String scheme) throws Exception {
+ System.out.println("Provider Info for scheme \"" + scheme + "\":");
+ Collection<Capability> caps;
+ caps = mgr.getProviderCapabilities(scheme);
+ if (caps != null && !caps.isEmpty()) {
+ System.out.println(" capabilities: " + caps);
+ }
+ FileOperationProvider[] ops = mgr.getOperationProviders(scheme);
+ if (ops != null && ops.length > 0) {
+ System.out.println(" operations: " + ops);
+ }
}
/**
* Does a 'help' command.
*/
- private void help()
- {
+ private void help() {
System.out.println("Commands:");
System.out.println("cat <file> Displays the contents of a
file.");
System.out.println("cd [folder] Changes current folder.");
@@ -230,10 +178,8 @@ public final class Shell
/**
* Does an 'rm' command.
*/
- private void rm(final String[] cmd) throws Exception
- {
- if (cmd.length < 2)
- {
+ private void rm(final String[] cmd) throws Exception {
+ if (cmd.length < 2) {
throw new Exception("USAGE: rm <path>");
}
@@ -244,17 +190,14 @@ public final class Shell
/**
* Does a 'cp' command.
*/
- private void cp(final String[] cmd) throws Exception
- {
- if (cmd.length < 3)
- {
+ private void cp(final String[] cmd) throws Exception {
+ if (cmd.length < 3) {
throw new Exception("USAGE: cp <src> <dest>");
}
final FileObject src = mgr.resolveFile(cwd, cmd[1]);
FileObject dest = mgr.resolveFile(cwd, cmd[2]);
- if (dest.exists() && dest.getType() == FileType.FOLDER)
- {
+ if (dest.exists() && dest.getType() == FileType.FOLDER) {
dest = dest.resolveFile(src.getName().getBaseName());
}
@@ -264,10 +207,8 @@ public final class Shell
/**
* Does a 'cat' command.
*/
- private void cat(final String[] cmd) throws Exception
- {
- if (cmd.length < 2)
- {
+ private void cat(final String[] cmd) throws Exception {
+ if (cmd.length < 2) {
throw new Exception("USAGE: cat <path>");
}
@@ -282,35 +223,26 @@ public final class Shell
/**
* Does a 'pwd' command.
*/
- private void pwd()
- {
+ private void pwd() {
System.out.println("Current folder is " + cwd.getName());
}
/**
- * Does a 'cd' command.
- * If the taget directory does not exist, a message is printed to
<code>System.err</code>.
+ * Does a 'cd' command. If the taget directory does not exist, a message
is printed to <code>System.err</code>.
*/
- private void cd(final String[] cmd) throws Exception
- {
+ private void cd(final String[] cmd) throws Exception {
final String path;
- if (cmd.length > 1)
- {
+ if (cmd.length > 1) {
path = cmd[1];
- }
- else
- {
+ } else {
path = System.getProperty("user.home");
}
// Locate and validate the folder
final FileObject tmp = mgr.resolveFile(cwd, path);
- if (tmp.exists())
- {
+ if (tmp.exists()) {
cwd = tmp;
- }
- else
- {
+ } else {
System.out.println("Folder does not exist: " + tmp.getName());
}
System.out.println("Current folder is " + cwd.getName());
@@ -319,38 +251,28 @@ public final class Shell
/**
* Does an 'ls' command.
*/
- private void ls(final String[] cmd) throws FileSystemException
- {
+ private void ls(final String[] cmd) throws FileSystemException {
int pos = 1;
final boolean recursive;
- if (cmd.length > pos && cmd[pos].equals("-R"))
- {
+ if (cmd.length > pos && cmd[pos].equals("-R")) {
recursive = true;
pos++;
- }
- else
- {
+ } else {
recursive = false;
}
final FileObject file;
- if (cmd.length > pos)
- {
+ if (cmd.length > pos) {
file = mgr.resolveFile(cwd, cmd[pos]);
- }
- else
- {
+ } else {
file = cwd;
}
- if (file.getType() == FileType.FOLDER)
- {
+ if (file.getType() == FileType.FOLDER) {
// List the contents
System.out.println("Contents of " + file.getName());
listChildren(file, recursive, "");
- }
- else
- {
+ } else {
// Stat the file
System.out.println(file.getName());
final FileContent content = file.getContent();
@@ -364,15 +286,12 @@ public final class Shell
/**
* Does a 'touch' command.
*/
- private void touch(final String[] cmd) throws Exception
- {
- if (cmd.length < 2)
- {
+ private void touch(final String[] cmd) throws Exception {
+ if (cmd.length < 2) {
throw new Exception("USAGE: touch <path>");
}
final FileObject file = mgr.resolveFile(cwd, cmd[1]);
- if (!file.exists())
- {
+ if (!file.exists()) {
file.createFile();
}
file.getContent().setLastModifiedTime(System.currentTimeMillis());
@@ -381,26 +300,18 @@ public final class Shell
/**
* Lists the children of a folder.
*/
- private void listChildren(final FileObject dir,
- final boolean recursive,
- final String prefix)
- throws FileSystemException
- {
+ private void listChildren(final FileObject dir, final boolean recursive,
final String prefix)
+ throws FileSystemException {
final FileObject[] children = dir.getChildren();
- for (final FileObject child : children)
- {
+ for (final FileObject child : children) {
System.out.print(prefix);
System.out.print(child.getName().getBaseName());
- if (child.getType() == FileType.FOLDER)
- {
+ if (child.getType() == FileType.FOLDER) {
System.out.println("/");
- if (recursive)
- {
+ if (recursive) {
listChildren(child, recursive, prefix + " ");
}
- }
- else
- {
+ } else {
System.out.println();
}
}
@@ -409,31 +320,24 @@ public final class Shell
/**
* Returns the next command, split into tokens.
*/
- private String[] nextCommand() throws IOException
- {
+ private String[] nextCommand() throws IOException {
System.out.print("> ");
final String line = reader.readLine();
- if (line == null)
- {
+ if (line == null) {
return null;
}
final ArrayList<String> cmd = new ArrayList<>();
final StringTokenizer tokens = new StringTokenizer(line);
- while (tokens.hasMoreTokens())
- {
+ while (tokens.hasMoreTokens()) {
cmd.add(tokens.nextToken());
}
return cmd.toArray(new String[cmd.size()]);
}
- private static String getVersion(Class<?> cls)
- {
- try
- {
+ private static String getVersion(Class<?> cls) {
+ try {
return cls.getPackage().getImplementationVersion();
- }
- catch (Exception ignored)
- {
+ } catch (Exception ignored) {
return "N/A";
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ShowProperties.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ShowProperties.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ShowProperties.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ShowProperties.java
Thu Sep 14 19:43:40 2017
@@ -28,28 +28,22 @@ import org.apache.commons.vfs2.VFS;
/**
* Example which prints all properties of the file passed as first parameter.
*/
-public final class ShowProperties
-{
+public final class ShowProperties {
/** Maximum number of children to show. */
private static final int SHOW_MAX = 5;
- private ShowProperties()
- {
+ private ShowProperties() {
/* main class not instantiated. */
}
- public static void main(final String[] args)
- {
- if (args.length == 0)
- {
+ public static void main(final String[] args) {
+ if (args.length == 0) {
System.err.println("Please pass the name of a file as parameter.");
System.err.println("e.g. java
org.apache.commons.vfs2.example.ShowProperties LICENSE.txt");
return;
}
- for (final String arg : args)
- {
- try
- {
+ for (final String arg : args) {
+ try {
final FileSystemManager mgr = VFS.getManager();
System.out.println();
System.out.println("Parsing: " + arg);
@@ -68,40 +62,29 @@ public final class ShowProperties
System.out.println("Readable: " + file.isReadable());
System.out.println("Writeable: " + file.isWriteable());
System.out.println("Root path: " +
file.getFileSystem().getRoot().getName().getPath());
- if (file.exists())
- {
- if (file.getType().equals(FileType.FILE))
- {
+ if (file.exists()) {
+ if (file.getType().equals(FileType.FILE)) {
System.out.println("Size: " +
file.getContent().getSize() + " bytes");
- }
- else if (file.getType().equals(FileType.FOLDER) &&
file.isReadable())
- {
+ } else if (file.getType().equals(FileType.FOLDER) &&
file.isReadable()) {
final FileObject[] children = file.getChildren();
System.out.println("Directory with " + children.length
+ " files");
- for (int iterChildren = 0; iterChildren <
children.length; iterChildren++)
- {
+ for (int iterChildren = 0; iterChildren <
children.length; iterChildren++) {
System.out.println("#" + iterChildren + ": " +
children[iterChildren].getName());
- if (iterChildren > SHOW_MAX)
- {
+ if (iterChildren > SHOW_MAX) {
break;
}
}
}
- System.out.println("Last modified: " +
DateFormat.getInstance().format(
- new
Date(file.getContent().getLastModifiedTime())));
- }
- else
- {
+ System.out.println("Last modified: "
+ + DateFormat.getInstance().format(new
Date(file.getContent().getLastModifiedTime())));
+ } else {
System.out.println("The file does not exist");
}
file.close();
- }
- catch (final FileSystemException ex)
- {
+ } catch (final FileSystemException ex) {
ex.printStackTrace();
}
}
}
}
-
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/FtpCheck.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/FtpCheck.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/FtpCheck.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/FtpCheck.java
Thu Sep 14 19:43:40 2017
@@ -26,67 +26,54 @@ import org.apache.commons.net.ftp.FTPRep
/**
* Basic check for FTP.
*/
-public final class FtpCheck
-{
- private FtpCheck()
- {
+public final class FtpCheck {
+ private FtpCheck() {
/* main class not instantiated. */
}
- public static void main(final String[] args) throws Exception
- {
- if (args.length < 3)
- {
+ public static void main(final String[] args) throws Exception {
+ if (args.length < 3) {
throw new IllegalArgumentException("Usage: FtpCheck user pass host
dir");
}
final String user = args[0];
final String pass = args[1];
final String host = args[2];
String dir = null;
- if (args.length == 4)
- {
+ if (args.length == 4) {
dir = args[3];
}
final FTPClient client = new FTPClient();
client.connect(host);
final int reply = client.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply))
- {
+ if (!FTPReply.isPositiveCompletion(reply)) {
throw new IllegalArgumentException("cant connect: " + reply);
}
- if (!client.login(user, pass))
- {
+ if (!client.login(user, pass)) {
throw new IllegalArgumentException("login failed");
}
client.enterLocalPassiveMode();
final OutputStream os = client.storeFileStream(dir + "/test.txt");
- if (os == null)
- {
+ if (os == null) {
throw new IllegalStateException(client.getReplyString());
}
os.write("test".getBytes(Charset.defaultCharset()));
os.close();
client.completePendingCommand();
- if (dir != null && !client.changeWorkingDirectory(dir))
- {
+ if (dir != null && !client.changeWorkingDirectory(dir)) {
throw new IllegalArgumentException("change dir to '" + dir + "'
failed");
}
System.err.println("System: " + client.getSystemType());
final FTPFile[] files = client.listFiles();
- for (int i = 0; i < files.length; i++)
- {
+ for (int i = 0; i < files.length; i++) {
final FTPFile file = files[i];
- if (file == null)
- {
+ if (file == null) {
System.err.println("#" + i + ": " + null);
- }
- else
- {
+ } else {
System.err.println("#" + i + ": " + file.getRawListing());
System.err.println("#" + i + ": " + file.toString());
System.err.println("\t name:" + file.getName() + " type:" +
file.getType());
Modified:
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/SftpCheck.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/SftpCheck.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/SftpCheck.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/libcheck/SftpCheck.java
Thu Sep 14 19:43:40 2017
@@ -28,17 +28,13 @@ import com.jcraft.jsch.UserInfo;
/**
* Basic check for SFTP.
*/
-public final class SftpCheck
-{
- private SftpCheck()
- {
+public final class SftpCheck {
+ private SftpCheck() {
/* main class not instantiated. */
}
- public static void main(final String[] args) throws Exception
- {
- if (args.length != 4)
- {
+ public static void main(final String[] args) throws Exception {
+ if (args.length != 4) {
throw new IllegalArgumentException("Usage: SftpCheck user pass
host dir");
}
final String user = args[0];
@@ -50,41 +46,34 @@ public final class SftpCheck
props.setProperty("StrictHostKeyChecking", "false");
final JSch jsch = new JSch();
final Session session = jsch.getSession(user, host, 22);
- session.setUserInfo(new UserInfo()
- {
+ session.setUserInfo(new UserInfo() {
@Override
- public String getPassphrase()
- {
+ public String getPassphrase() {
return null;
}
@Override
- public String getPassword()
- {
+ public String getPassword() {
return null;
}
@Override
- public boolean promptPassword(final String string)
- {
+ public boolean promptPassword(final String string) {
return false;
}
@Override
- public boolean promptPassphrase(final String string)
- {
+ public boolean promptPassphrase(final String string) {
return false;
}
@Override
- public boolean promptYesNo(final String string)
- {
+ public boolean promptYesNo(final String string) {
return true;
}
@Override
- public void showMessage(final String string)
- {
+ public void showMessage(final String string) {
}
});
session.setPassword(pass);
@@ -93,8 +82,7 @@ public final class SftpCheck
chan.connect();
final Vector<?> list = chan.ls(dir);
final Iterator<?> iterList = list.iterator();
- while (iterList.hasNext())
- {
+ while (iterList.hasNext()) {
System.err.println(iterList.next());
}
System.err.println("done");
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeAttributesMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeAttributesMap.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeAttributesMap.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeAttributesMap.java
Thu Sep 14 19:43:40 2017
@@ -41,8 +41,7 @@ import org.apache.commons.logging.LogFac
/**
* A map which tries to allow access to the various aspects of the mail.
*/
-public class MimeAttributesMap implements Map<String, Object>
-{
+public class MimeAttributesMap implements Map<String, Object> {
private static final String OBJECT_PREFIX = "obj.";
private final Log log = LogFactory.getLog(MimeAttributesMap.class);
@@ -51,155 +50,113 @@ public class MimeAttributesMap implement
private Map<String, Object> backingMap;
-
- public MimeAttributesMap(final Part part)
- {
+ public MimeAttributesMap(final Part part) {
this.part = part;
addMimeMessageMethod(part.getClass().getMethods());
addMimeMessageMethod(part.getClass().getDeclaredMethods());
}
- private void addMimeMessageMethod(final Method[] methods)
- {
- for (final Method method : methods)
- {
- if (!Modifier.isPublic(method.getModifiers()))
- {
+ private void addMimeMessageMethod(final Method[] methods) {
+ for (final Method method : methods) {
+ if (!Modifier.isPublic(method.getModifiers())) {
continue;
}
- if (method.getParameterTypes().length > 0)
- {
+ if (method.getParameterTypes().length > 0) {
continue;
}
- if (method.getName().startsWith("get"))
- {
+ if (method.getName().startsWith("get")) {
mimeMessageGetters.put(method.getName().substring(3), method);
- }
- else if (method.getName().startsWith("is"))
- {
+ } else if (method.getName().startsWith("is")) {
mimeMessageGetters.put(method.getName().substring(2), method);
}
}
}
- private Map<String, Object> getMap()
- {
- if (backingMap == null)
- {
+ private Map<String, Object> getMap() {
+ if (backingMap == null) {
backingMap = createMap();
}
return backingMap;
}
- private Map<String, Object> createMap()
- {
+ private Map<String, Object> createMap() {
// Object is either a String, or a List of Strings
final Map<String, Object> ret = new TreeMap<>();
Enumeration<Header> headers;
- try
- {
+ try {
@SuppressWarnings("unchecked") // Javadoc say Part returns Header
- final
- Enumeration<Header> allHeaders = part.getAllHeaders();
+ final Enumeration<Header> allHeaders = part.getAllHeaders();
headers = allHeaders;
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
throw new RuntimeException(e);
}
// add all headers
- while (headers.hasMoreElements())
- {
+ while (headers.hasMoreElements()) {
final Header header = headers.nextElement();
final String headerName = header.getName();
final Object values = ret.get(headerName);
- if (values == null)
- {
+ if (values == null) {
ret.put(headerName, header.getValue());
- }
- else if (values instanceof String)
- {
+ } else if (values instanceof String) {
final ArrayList<String> newValues = new ArrayList<>();
newValues.add((String) values);
newValues.add(header.getValue());
ret.put(headerName, newValues);
- }
- else if (values instanceof List)
- {
+ } else if (values instanceof List) {
@SuppressWarnings("unchecked") // we only add Strings to the
Lists
- final
- List<String> list = (List<String>) values;
+ final List<String> list = (List<String>) values;
list.add(header.getValue());
}
}
// add all simple get/is results (with obj. prefix)
final Iterator<Entry<String, Method>> iterEntries =
mimeMessageGetters.entrySet().iterator();
- while (iterEntries.hasNext())
- {
+ while (iterEntries.hasNext()) {
final Map.Entry<String, Method> entry = iterEntries.next();
final String name = entry.getKey();
final Method method = entry.getValue();
- try
- {
+ try {
final Object value = method.invoke(part);
ret.put(OBJECT_PREFIX + name, value);
- }
- catch (final IllegalAccessException e)
- {
+ } catch (final IllegalAccessException e) {
log.debug(e.getLocalizedMessage(), e);
- }
- catch (final InvocationTargetException e)
- {
+ } catch (final InvocationTargetException e) {
log.debug(e.getLocalizedMessage(), e);
}
}
// add extended fields (with obj. prefix too)
- if (part instanceof MimeMessage)
- {
+ if (part instanceof MimeMessage) {
final MimeMessage message = (MimeMessage) part;
- try
- {
+ try {
final Address[] address =
message.getRecipients(MimeMessage.RecipientType.BCC);
ret.put(OBJECT_PREFIX + "Recipients.BCC", address);
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
log.debug(e.getLocalizedMessage(), e);
}
- try
- {
+ try {
final Address[] address =
message.getRecipients(MimeMessage.RecipientType.CC);
ret.put(OBJECT_PREFIX + "Recipients.CC", address);
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
log.debug(e.getLocalizedMessage(), e);
}
- try
- {
+ try {
final Address[] address =
message.getRecipients(MimeMessage.RecipientType.TO);
ret.put(OBJECT_PREFIX + "Recipients.TO", address);
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
log.debug(e.getLocalizedMessage(), e);
}
- try
- {
+ try {
final Address[] address =
message.getRecipients(MimeMessage.RecipientType.NEWSGROUPS);
ret.put(OBJECT_PREFIX + "Recipients.NEWSGROUPS", address);
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
log.debug(e.getLocalizedMessage(), e);
}
}
@@ -207,63 +164,51 @@ public class MimeAttributesMap implement
return ret;
}
- public int size()
- {
+ public int size() {
return getMap().size();
}
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
return getMap().size() < 1;
}
- public boolean containsKey(final Object key)
- {
+ public boolean containsKey(final Object key) {
return getMap().containsKey(key);
}
- public boolean containsValue(final Object value)
- {
+ public boolean containsValue(final Object value) {
return getMap().containsValue(value);
}
- public Object get(final Object key)
- {
+ public Object get(final Object key) {
return getMap().get(key);
}
- public Object put(final String key, final Object value)
- {
+ public Object put(final String key, final Object value) {
throw new UnsupportedOperationException();
}
- public Object remove(final Object key)
- {
+ public Object remove(final Object key) {
throw new UnsupportedOperationException();
}
- public void putAll(final Map<? extends String, ? extends Object> t)
- {
+ public void putAll(final Map<? extends String, ? extends Object> t) {
throw new UnsupportedOperationException();
}
- public void clear()
- {
+ public void clear() {
throw new UnsupportedOperationException();
}
- public Set<String> keySet()
- {
+ public Set<String> keySet() {
return Collections.unmodifiableSet(getMap().keySet());
}
- public Collection<Object> values()
- {
+ public Collection<Object> values() {
return Collections.unmodifiableCollection(getMap().values());
}
- public Set<Entry<String, Object>> entrySet()
- {
+ public Set<Entry<String, Object>> entrySet() {
return Collections.unmodifiableSet(getMap().entrySet());
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileContentInfoFactory.java
Thu Sep 14 19:43:40 2017
@@ -29,21 +29,17 @@ import org.apache.commons.vfs2.impl.Defa
/**
* Get access to the content info stuff for mime objects.
*/
-public class MimeFileContentInfoFactory implements FileContentInfoFactory
-{
- public FileContentInfo create(final FileContent fileContent) throws
FileSystemException
- {
+public class MimeFileContentInfoFactory implements FileContentInfoFactory {
+ public FileContentInfo create(final FileContent fileContent) throws
FileSystemException {
final MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
final Part part = mimeFile.getPart();
String contentTypeString = null;
String charset = null;
- try
- {
+ try {
// special handling for multipart
- if (mimeFile.isMultipart())
- {
+ if (mimeFile.isMultipart()) {
// get the original content type, but ...
contentTypeString = part.getContentType();
@@ -51,44 +47,32 @@ public class MimeFileContentInfoFactory
// the preamble will be delivered in UTF-8 - fixed
charset = MimeFileSystem.PREAMBLE_CHARSET;
}
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
throw new FileSystemException(e);
}
- if (contentTypeString == null)
- {
+ if (contentTypeString == null) {
// normal message ... get the content type
- try
- {
+ try {
contentTypeString = part.getContentType();
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
throw new FileSystemException(e);
}
}
ContentType contentType;
- try
- {
+ try {
contentType = new ContentType(contentTypeString);
- }
- catch (final MessagingException e)
- {
+ } catch (final MessagingException e) {
throw new FileSystemException(e);
}
- if (charset == null)
- {
+ if (charset == null) {
// charset might already be set by the multipart message stuff,
else
// extract it from the contentType now
charset = contentType.getParameter("charset"); // NON-NLS
}
- return new DefaultFileContentInfo(
- contentType.getBaseType(),
- charset);
+ return new DefaultFileContentInfo(contentType.getBaseType(), charset);
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileObject.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileObject.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileObject.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileObject.java
Thu Sep 14 19:43:40 2017
@@ -44,30 +44,23 @@ import org.apache.commons.vfs2.util.File
/**
* A part of a MIME message.
*/
-public class MimeFileObject
- extends AbstractFileObject<MimeFileSystem>
- implements FileObject
-{
+public class MimeFileObject extends AbstractFileObject<MimeFileSystem>
implements FileObject {
private Part part;
private Map<String, Object> attributeMap;
- protected MimeFileObject(final AbstractFileName name,
- final Part part,
- final MimeFileSystem fileSystem) throws
FileSystemException
- {
+ protected MimeFileObject(final AbstractFileName name, final Part part,
final MimeFileSystem fileSystem)
+ throws FileSystemException {
super(name, fileSystem);
setPart(part);
}
+
/**
* Attaches this file object to its file resource.
*/
@Override
- protected void doAttach() throws Exception
- {
- if (part == null)
- {
- if (!getName().equals(getFileSystem().getRootName()))
- {
+ protected void doAttach() throws Exception {
+ if (part == null) {
+ if (!getName().equals(getFileSystem().getRootName())) {
final MimeFileObject foParent = (MimeFileObject)
FileObjectUtils.getAbstractFileObject(getParent());
setPart(foParent.findPart(getName().getBaseName()));
return;
@@ -77,22 +70,17 @@ public class MimeFileObject
}
}
- private Part findPart(final String partName) throws Exception
- {
- if (getType() == FileType.IMAGINARY)
- {
+ private Part findPart(final String partName) throws Exception {
+ if (getType() == FileType.IMAGINARY) {
// not existent
return null;
}
- if (isMultipart())
- {
- final Multipart multipart = (Multipart) part.getContent();
- if (partName.startsWith(MimeFileSystem.NULL_BP_NAME))
- {
+ if (isMultipart()) {
+ final Multipart multipart = (Multipart) part.getContent();
+ if (partName.startsWith(MimeFileSystem.NULL_BP_NAME)) {
final int partNumber =
Integer.parseInt(partName.substring(MimeFileSystem.NULL_BP_NAME.length()), 10);
- if (partNumber < 0 || partNumber + 1 > multipart.getCount())
- {
+ if (partNumber < 0 || partNumber + 1 > multipart.getCount()) {
// non existent
return null;
}
@@ -100,11 +88,9 @@ public class MimeFileObject
return multipart.getBodyPart(partNumber);
}
- for (int i = 0; i < multipart.getCount(); i++)
- {
+ for (int i = 0; i < multipart.getCount(); i++) {
final Part childPart = multipart.getBodyPart(i);
- if (partName.equals(childPart.getFileName()))
- {
+ if (partName.equals(childPart.getFileName())) {
return childPart;
}
}
@@ -114,24 +100,19 @@ public class MimeFileObject
}
@Override
- protected void doDetach() throws Exception
- {
+ protected void doDetach() throws Exception {
}
/**
- * Determines the type of the file, returns null if the file does not
- * exist.
+ * Determines the type of the file, returns null if the file does not
exist.
*/
@Override
- protected FileType doGetType() throws Exception
- {
- if (part == null)
- {
+ protected FileType doGetType() throws Exception {
+ if (part == null) {
return FileType.IMAGINARY;
}
- if (isMultipart())
- {
+ if (isMultipart()) {
// we cant have children ...
return FileType.FILE_OR_FOLDER;
}
@@ -140,46 +121,37 @@ public class MimeFileObject
}
@Override
- protected String[] doListChildren() throws Exception
- {
+ protected String[] doListChildren() throws Exception {
return null;
}
/**
- * Lists the children of the file. Is only called if {@link #doGetType}
- * returns {@link org.apache.commons.vfs2.FileType#FOLDER}.
+ * Lists the children of the file. Is only called if {@link #doGetType}
returns
+ * {@link org.apache.commons.vfs2.FileType#FOLDER}.
*/
@Override
- protected FileObject[] doListChildrenResolved() throws Exception
- {
- if (part == null)
- {
+ protected FileObject[] doListChildrenResolved() throws Exception {
+ if (part == null) {
return null;
}
final List<MimeFileObject> vfs = new ArrayList<>();
- if (isMultipart())
- {
+ if (isMultipart()) {
final Object container = part.getContent();
- if (container instanceof Multipart)
- {
+ if (container instanceof Multipart) {
final Multipart multipart = (Multipart) container;
- for (int i = 0; i < multipart.getCount(); i++)
- {
+ for (int i = 0; i < multipart.getCount(); i++) {
final Part part = multipart.getBodyPart(i);
String filename = UriParser.encode(part.getFileName());
- if (filename == null)
- {
+ if (filename == null) {
filename = MimeFileSystem.NULL_BP_NAME + i;
}
- final MimeFileObject fo = (MimeFileObject)
FileObjectUtils.getAbstractFileObject(
- getFileSystem().resolveFile(
-
getFileSystem().getFileSystemManager().resolveName(getName(),
- filename,
- NameScope.CHILD)));
+ final MimeFileObject fo = (MimeFileObject) FileObjectUtils
+
.getAbstractFileObject(getFileSystem().resolveFile(getFileSystem().getFileSystemManager()
+ .resolveName(getName(), filename,
NameScope.CHILD)));
fo.setPart(part);
vfs.add(fo);
}
@@ -189,8 +161,7 @@ public class MimeFileObject
return vfs.toArray(new MimeFileObject[vfs.size()]);
}
- private void setPart(final Part part)
- {
+ private void setPart(final Part part) {
this.part = part;
this.attributeMap = null;
}
@@ -199,8 +170,7 @@ public class MimeFileObject
* Returns the size of the file content (in bytes).
*/
@Override
- protected long doGetContentSize() throws Exception
- {
+ protected long doGetContentSize() throws Exception {
return part.getSize();
}
@@ -208,29 +178,22 @@ public class MimeFileObject
* Returns the last modified time of this file.
*/
@Override
- protected long doGetLastModifiedTime()
- throws Exception
- {
+ protected long doGetLastModifiedTime() throws Exception {
final Message mm = getMessage();
- if (mm == null)
- {
+ if (mm == null) {
return -1;
}
- if (mm.getSentDate() != null)
- {
+ if (mm.getSentDate() != null) {
return mm.getSentDate().getTime();
}
- if (mm.getReceivedDate() != null)
- {
+ if (mm.getReceivedDate() != null) {
mm.getReceivedDate();
}
return 0;
}
- private Message getMessage() throws FileSystemException
- {
- if (part instanceof Message)
- {
+ private Message getMessage() throws FileSystemException {
+ if (part instanceof Message) {
return (Message) part;
}
@@ -241,16 +204,13 @@ public class MimeFileObject
* Creates an input stream to read the file content from.
*/
@Override
- protected InputStream doGetInputStream() throws Exception
- {
- if (isMultipart())
- {
+ protected InputStream doGetInputStream() throws Exception {
+ if (isMultipart()) {
// deliver the preamble as the only content
final String preamble = ((MimeMultipart)
part.getContent()).getPreamble();
- if (preamble == null)
- {
- return new ByteArrayInputStream(new byte[]{});
+ if (preamble == null) {
+ return new ByteArrayInputStream(new byte[] {});
}
return new
ByteArrayInputStream(preamble.getBytes(MimeFileSystem.PREAMBLE_CHARSET));
}
@@ -258,19 +218,16 @@ public class MimeFileObject
return part.getInputStream();
}
- boolean isMultipart() throws MessagingException
- {
+ boolean isMultipart() throws MessagingException {
return part.getContentType() != null &&
part.getContentType().startsWith("multipart/");
}
@Override
- protected FileContentInfoFactory getFileContentInfoFactory()
- {
+ protected FileContentInfoFactory getFileContentInfoFactory() {
return new MimeFileContentInfoFactory();
}
- protected Part getPart()
- {
+ protected Part getPart() {
return part;
}
@@ -284,16 +241,11 @@ public class MimeFileObject
* </ul>
*/
@Override
- protected Map<String, Object> doGetAttributes() throws Exception
- {
- if (attributeMap == null)
- {
- if (part != null)
- {
+ protected Map<String, Object> doGetAttributes() throws Exception {
+ if (attributeMap == null) {
+ if (part != null) {
attributeMap = new MimeAttributesMap(part);
- }
- else
- {
+ } else {
attributeMap = Collections.emptyMap();
}
}
@@ -302,8 +254,7 @@ public class MimeFileObject
}
@SuppressWarnings("unchecked") // Javadoc says Part returns Header
- protected Enumeration<Header> getAllHeaders() throws MessagingException
- {
+ protected Enumeration<Header> getAllHeaders() throws MessagingException {
return part.getAllHeaders();
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileProvider.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileProvider.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileProvider.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileProvider.java
Thu Sep 14 19:43:40 2017
@@ -34,23 +34,12 @@ import org.apache.commons.vfs2.provider.
/**
* A provider for MIME Message.
*/
-public class MimeFileProvider
- extends AbstractLayeredFileProvider
- implements FileProvider
-{
- static final Collection<Capability> capabilities =
- Collections.unmodifiableCollection(Arrays.asList(new Capability[]
- {
- Capability.GET_TYPE,
- Capability.GET_LAST_MODIFIED,
- Capability.LIST_CHILDREN,
- Capability.READ_CONTENT,
- Capability.URI,
- Capability.ATTRIBUTES
- }));
+public class MimeFileProvider extends AbstractLayeredFileProvider implements
FileProvider {
+ static final Collection<Capability> capabilities = Collections
+ .unmodifiableCollection(Arrays.asList(new Capability[] {
Capability.GET_TYPE, Capability.GET_LAST_MODIFIED,
+ Capability.LIST_CHILDREN, Capability.READ_CONTENT,
Capability.URI, Capability.ATTRIBUTES }));
- public MimeFileProvider()
- {
+ public MimeFileProvider() {
super();
}
@@ -59,16 +48,12 @@ public class MimeFileProvider
*/
@Override
protected FileSystem doCreateFileSystem(final String scheme, final
FileObject file,
- final FileSystemOptions
fileSystemOptions)
- throws FileSystemException
- {
- final FileName name =
- new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH,
FileType.FOLDER);
+ final FileSystemOptions fileSystemOptions) throws
FileSystemException {
+ final FileName name = new LayeredFileName(scheme, file.getName(),
FileName.ROOT_PATH, FileType.FOLDER);
return new MimeFileSystem(name, file, fileSystemOptions);
}
- public Collection<Capability> getCapabilities()
- {
+ public Collection<Capability> getCapabilities() {
return capabilities;
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileSystem.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileSystem.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileSystem.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/mime/MimeFileSystem.java
Thu Sep 14 19:43:40 2017
@@ -38,9 +38,7 @@ import org.apache.commons.vfs2.util.Shar
/**
* An MIME file system.
*/
-public class MimeFileSystem
- extends AbstractFileSystem
-{
+public class MimeFileSystem extends AbstractFileSystem {
static final String NULL_BP_NAME = "_body_part_";
static final String CONTENT_NAME = "_content";
static final String PREAMBLE_CHARSET = "UTF-8";
@@ -50,8 +48,7 @@ public class MimeFileSystem
private InputStream mimeStream = null;
protected MimeFileSystem(final FileName rootName, final FileObject
parentLayer,
- final FileSystemOptions fileSystemOptions)
- {
+ final FileSystemOptions fileSystemOptions) {
super(rootName, parentLayer, fileSystemOptions);
}
@@ -59,8 +56,7 @@ public class MimeFileSystem
* Creates a file object.
*/
@Override
- protected FileObject createFile(final AbstractFileName name) throws
FileSystemException
- {
+ protected FileObject createFile(final AbstractFileName name) throws
FileSystemException {
return new MimeFileObject(name, null, this);
}
@@ -68,62 +64,45 @@ public class MimeFileSystem
* Returns the capabilities of this file system.
*/
@Override
- protected void addCapabilities(final Collection<Capability> caps)
- {
+ protected void addCapabilities(final Collection<Capability> caps) {
caps.addAll(MimeFileProvider.capabilities);
}
-
@Override
- protected void doCloseCommunicationLink()
- {
- try
- {
- if (mimeStream == null)
- {
+ protected void doCloseCommunicationLink() {
+ try {
+ if (mimeStream == null) {
return;
}
closeMimeStream();
mimeStream = null;
- }
- catch (final IOException e)
- {
+ } catch (final IOException e) {
log.warn(e.getLocalizedMessage(), e);
}
}
- private void closeMimeStream() throws IOException
- {
- if (mimeStream instanceof SharedRandomContentInputStream)
- {
+ private void closeMimeStream() throws IOException {
+ if (mimeStream instanceof SharedRandomContentInputStream) {
((SharedRandomContentInputStream) mimeStream).closeAll();
- }
- else
- {
+ } else {
mimeStream.close();
}
}
- public Part createCommunicationLink() throws IOException,
MessagingException
- {
- if (mimeStream != null)
- {
+ public Part createCommunicationLink() throws IOException,
MessagingException {
+ if (mimeStream != null) {
closeMimeStream();
}
final FileObject parentLayer = getParentLayer();
- if (!parentLayer.exists())
- {
+ if (!parentLayer.exists()) {
return null;
}
- if
(parentLayer.getFileSystem().hasCapability(Capability.RANDOM_ACCESS_READ))
- {
+ if
(parentLayer.getFileSystem().hasCapability(Capability.RANDOM_ACCESS_READ)) {
mimeStream = new SharedRandomContentInputStream(parentLayer);
- }
- else
- {
+ } else {
mimeStream = getParentLayer().getContent().getInputStream();
}
return new MimeMessage(null, mimeStream);
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileName.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileName.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileName.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileName.java
Thu Sep 14 19:43:40 2017
@@ -22,27 +22,17 @@ import org.apache.commons.vfs2.FileType;
import org.apache.commons.vfs2.provider.GenericFileName;
/**
- * An SMB URI. Adds a share name to the generic URI.
+ * An SMB URI. Adds a share name to the generic URI.
*/
-public class SmbFileName extends GenericFileName
-{
+public class SmbFileName extends GenericFileName {
private static final int DEFAULT_PORT = 139;
private final String share;
private final String domain;
private String uriWithoutAuth;
- protected SmbFileName(
- final String scheme,
- final String hostName,
- final int port,
- final String userName,
- final String password,
- final String domain,
- final String share,
- final String path,
- final FileType type)
- {
+ protected SmbFileName(final String scheme, final String hostName, final
int port, final String userName,
+ final String password, final String domain, final String share,
final String path, final FileType type) {
super(scheme, hostName, port, DEFAULT_PORT, userName, password, path,
type);
this.share = share;
this.domain = domain;
@@ -50,10 +40,10 @@ public class SmbFileName extends Generic
/**
* Returns the share name.
+ *
* @return share name
*/
- public String getShare()
- {
+ public String getShare() {
return share;
}
@@ -61,8 +51,7 @@ public class SmbFileName extends Generic
* Builds the root URI for this file name.
*/
@Override
- protected void appendRootUri(final StringBuilder buffer, final boolean
addPassword)
- {
+ protected void appendRootUri(final StringBuilder buffer, final boolean
addPassword) {
super.appendRootUri(buffer, addPassword);
buffer.append('/');
buffer.append(share);
@@ -74,11 +63,8 @@ public class SmbFileName extends Generic
* Uses super method to add password or password placeholder.
*/
@Override
- protected void appendCredentials(final StringBuilder buffer, final boolean
addPassword)
- {
- if (getDomain() != null && getDomain().length() != 0 &&
- getUserName() != null && getUserName().length() != 0)
- {
+ protected void appendCredentials(final StringBuilder buffer, final boolean
addPassword) {
+ if (getDomain() != null && getDomain().length() != 0 && getUserName()
!= null && getUserName().length() != 0) {
buffer.append(getDomain());
buffer.append("\\");
}
@@ -93,18 +79,9 @@ public class SmbFileName extends Generic
* @return new SmbFileName object, never null.
*/
@Override
- public FileName createName(final String path, final FileType type)
- {
- return new SmbFileName(
- getScheme(),
- getHostName(),
- getPort(),
- getUserName(),
- getPassword(),
- domain,
- share,
- path,
- type);
+ public FileName createName(final String path, final FileType type) {
+ return new SmbFileName(getScheme(), getHostName(), getPort(),
getUserName(), getPassword(), domain, share, path,
+ type);
}
/**
@@ -113,10 +90,8 @@ public class SmbFileName extends Generic
* @return caches and return URI with no username/password, never null
* @throws FileSystemException if any of the invoked methods throw
*/
- public String getUriWithoutAuth() throws FileSystemException
- {
- if (uriWithoutAuth != null)
- {
+ public String getUriWithoutAuth() throws FileSystemException {
+ if (uriWithoutAuth != null) {
return uriWithoutAuth;
}
@@ -124,8 +99,7 @@ public class SmbFileName extends Generic
sb.append(getScheme());
sb.append("://");
sb.append(getHostName());
- if (getPort() != DEFAULT_PORT)
- {
+ if (getPort() != DEFAULT_PORT) {
sb.append(":");
sb.append(getPort());
}
@@ -138,10 +112,10 @@ public class SmbFileName extends Generic
/**
* Returns the domain name.
+ *
* @return domain name
*/
- public String getDomain()
- {
+ public String getDomain() {
return domain;
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileNameParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileNameParser.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileNameParser.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileNameParser.java
Thu Sep 14 19:43:40 2017
@@ -27,25 +27,21 @@ import org.apache.commons.vfs2.provider.
/**
* Implementation for sftp. set default port to 139
*/
-public class SmbFileNameParser extends URLFileNameParser
-{
+public class SmbFileNameParser extends URLFileNameParser {
private static final SmbFileNameParser INSTANCE = new SmbFileNameParser();
private static final int SMB_PORT = 139;
- public SmbFileNameParser()
- {
+ public SmbFileNameParser() {
super(SMB_PORT);
}
- public static FileNameParser getInstance()
- {
+ public static FileNameParser getInstance() {
return INSTANCE;
}
@Override
- public FileName parseUri(final VfsComponentContext context, final FileName
base,
- final String filename) throws FileSystemException
- {
+ public FileName parseUri(final VfsComponentContext context, final FileName
base, final String filename)
+ throws FileSystemException {
final StringBuilder name = new StringBuilder();
// Extract the scheme and authority parts
@@ -54,8 +50,7 @@ public class SmbFileNameParser extends U
// extract domain
String username = auth.getUserName();
final String domain = extractDomain(username);
- if (domain != null)
- {
+ if (domain != null) {
username = username.substring(domain.length() + 1);
}
@@ -65,39 +60,26 @@ public class SmbFileNameParser extends U
// Extract the share
final String share = UriParser.extractFirstElement(name);
- if (share == null || share.length() == 0)
- {
+ if (share == null || share.length() == 0) {
throw new
FileSystemException("vfs.provider.smb/missing-share-name.error", filename);
}
- // Normalise the path. Do this after extracting the share name,
+ // Normalise the path. Do this after extracting the share name,
// to deal with things like smb://hostname/share/..
final FileType fileType = UriParser.normalisePath(name);
final String path = name.toString();
- return new SmbFileName(
- auth.getScheme(),
- auth.getHostName(),
- auth.getPort(),
- username,
- auth.getPassword(),
- domain,
- share,
- path,
- fileType);
+ return new SmbFileName(auth.getScheme(), auth.getHostName(),
auth.getPort(), username, auth.getPassword(),
+ domain, share, path, fileType);
}
- private String extractDomain(final String username)
- {
- if (username == null)
- {
+ private String extractDomain(final String username) {
+ if (username == null) {
return null;
}
- for (int i = 0; i < username.length(); i++)
- {
- if (username.charAt(i) == '\\')
- {
+ for (int i = 0; i < username.length(); i++) {
+ if (username.charAt(i) == '\\') {
return username.substring(0, i);
}
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileObject.java
Thu Sep 14 19:43:40 2017
@@ -42,15 +42,11 @@ import org.apache.commons.vfs2.util.User
/**
* A file in an SMB file system.
*/
-public class SmbFileObject
- extends AbstractFileObject<SmbFileSystem>
-{
+public class SmbFileObject extends AbstractFileObject<SmbFileSystem> {
// private final String fileName;
private SmbFile file;
- protected SmbFileObject(final AbstractFileName name,
- final SmbFileSystem fileSystem) throws
FileSystemException
- {
+ protected SmbFileObject(final AbstractFileName name, final SmbFileSystem
fileSystem) throws FileSystemException {
super(name, fileSystem);
// this.fileName = UriParser.decode(name.getURI());
}
@@ -59,50 +55,42 @@ public class SmbFileObject
* Attaches this file object to its file resource.
*/
@Override
- protected void doAttach() throws Exception
- {
+ protected void doAttach() throws Exception {
// Defer creation of the SmbFile to here
- if (file == null)
- {
+ if (file == null) {
file = createSmbFile(getName());
}
}
@Override
- protected void doDetach() throws Exception
- {
+ protected void doDetach() throws Exception {
// file closed through content-streams
file = null;
}
private SmbFile createSmbFile(final FileName fileName)
- throws MalformedURLException, SmbException, FileSystemException
- {
+ throws MalformedURLException, SmbException, FileSystemException {
final SmbFileName smbFileName = (SmbFileName) fileName;
final String path = smbFileName.getUriWithoutAuth();
UserAuthenticationData authData = null;
SmbFile file;
- try
- {
- authData = UserAuthenticatorUtils.authenticate(
- getFileSystem().getFileSystemOptions(),
- SmbFileProvider.AUTHENTICATOR_TYPES);
+ try {
+ authData =
UserAuthenticatorUtils.authenticate(getFileSystem().getFileSystemOptions(),
+ SmbFileProvider.AUTHENTICATOR_TYPES);
NtlmPasswordAuthentication auth = null;
- if (authData != null)
- {
+ if (authData != null) {
auth = new NtlmPasswordAuthentication(
- UserAuthenticatorUtils.toString(
- UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.DOMAIN,
-
UserAuthenticatorUtils.toChar(smbFileName.getDomain()))),
- UserAuthenticatorUtils.toString(
- UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.USERNAME,
-
UserAuthenticatorUtils.toChar(smbFileName.getUserName()))),
- UserAuthenticatorUtils.toString(
- UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.PASSWORD,
-
UserAuthenticatorUtils.toChar(smbFileName.getPassword()))));
+
UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData,
+ UserAuthenticationData.DOMAIN,
UserAuthenticatorUtils.toChar(smbFileName.getDomain()))),
+ UserAuthenticatorUtils
+
.toString(UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.USERNAME,
+
UserAuthenticatorUtils.toChar(smbFileName.getUserName()))),
+ UserAuthenticatorUtils
+
.toString(UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.PASSWORD,
+
UserAuthenticatorUtils.toChar(smbFileName.getPassword()))));
}
// if auth == null SmbFile uses default credentials
@@ -111,35 +99,25 @@ public class SmbFileObject
// ANONYMOUS=("","","")
file = new SmbFile(path, auth);
- if (file.isDirectory() && !file.toString().endsWith("/"))
- {
+ if (file.isDirectory() && !file.toString().endsWith("/")) {
file = new SmbFile(path + "/", auth);
}
return file;
- }
- finally
- {
+ } finally {
UserAuthenticatorUtils.cleanup(authData); // might be null
}
}
/**
- * Determines the type of the file, returns null if the file does not
- * exist.
+ * Determines the type of the file, returns null if the file does not
exist.
*/
@Override
- protected FileType doGetType() throws Exception
- {
- if (!file.exists())
- {
+ protected FileType doGetType() throws Exception {
+ if (!file.exists()) {
return FileType.IMAGINARY;
- }
- else if (file.isDirectory())
- {
+ } else if (file.isDirectory()) {
return FileType.FOLDER;
- }
- else if (file.isFile())
- {
+ } else if (file.isFile()) {
return FileType.FILE;
}
@@ -147,15 +125,12 @@ public class SmbFileObject
}
/**
- * Lists the children of the file. Is only called if {@link #doGetType}
- * returns {@link FileType#FOLDER}.
+ * Lists the children of the file. Is only called if {@link #doGetType}
returns {@link FileType#FOLDER}.
*/
@Override
- protected String[] doListChildren() throws Exception
- {
+ protected String[] doListChildren() throws Exception {
// VFS-210: do not try to get listing for anything else than
directories
- if (!file.isDirectory())
- {
+ if (!file.isDirectory()) {
return null;
}
@@ -166,8 +141,7 @@ public class SmbFileObject
* Determines if this file is hidden.
*/
@Override
- protected boolean doIsHidden() throws Exception
- {
+ protected boolean doIsHidden() throws Exception {
return file.isHidden();
}
@@ -175,14 +149,12 @@ public class SmbFileObject
* Deletes the file.
*/
@Override
- protected void doDelete() throws Exception
- {
+ protected void doDelete() throws Exception {
file.delete();
}
@Override
- protected void doRename(final FileObject newfile) throws Exception
- {
+ protected void doRename(final FileObject newfile) throws Exception {
file.renameTo(createSmbFile(newfile.getName()));
}
@@ -190,8 +162,7 @@ public class SmbFileObject
* Creates this file as a folder.
*/
@Override
- protected void doCreateFolder() throws Exception
- {
+ protected void doCreateFolder() throws Exception {
file.mkdir();
file = createSmbFile(getName());
}
@@ -200,8 +171,7 @@ public class SmbFileObject
* Returns the size of the file content (in bytes).
*/
@Override
- protected long doGetContentSize() throws Exception
- {
+ protected long doGetContentSize() throws Exception {
return file.length();
}
@@ -209,9 +179,7 @@ public class SmbFileObject
* Returns the last modified time of this file.
*/
@Override
- protected long doGetLastModifiedTime()
- throws Exception
- {
+ protected long doGetLastModifiedTime() throws Exception {
return file.getLastModified();
}
@@ -219,20 +187,13 @@ public class SmbFileObject
* Creates an input stream to read the file content from.
*/
@Override
- protected InputStream doGetInputStream() throws Exception
- {
- try
- {
+ protected InputStream doGetInputStream() throws Exception {
+ try {
return new SmbFileInputStream(file);
- }
- catch (final SmbException e)
- {
- if (e.getNtStatus() == SmbException.NT_STATUS_NO_SUCH_FILE)
- {
+ } catch (final SmbException e) {
+ if (e.getNtStatus() == SmbException.NT_STATUS_NO_SUCH_FILE) {
throw new
org.apache.commons.vfs2.FileNotFoundException(getName());
- }
- else if (file.isDirectory())
- {
+ } else if (file.isDirectory()) {
throw new FileTypeHasNoContentException(getName());
}
@@ -244,8 +205,7 @@ public class SmbFileObject
* Creates an output stream to write the file content to.
*/
@Override
- protected OutputStream doGetOutputStream(final boolean bAppend) throws
Exception
- {
+ protected OutputStream doGetOutputStream(final boolean bAppend) throws
Exception {
return new SmbFileOutputStream(file, bAppend);
}
@@ -253,14 +213,12 @@ public class SmbFileObject
* random access
*/
@Override
- protected RandomAccessContent doGetRandomAccessContent(final
RandomAccessMode mode) throws Exception
- {
+ protected RandomAccessContent doGetRandomAccessContent(final
RandomAccessMode mode) throws Exception {
return new SmbFileRandomAccessContent(file, mode);
}
@Override
- protected boolean doSetLastModifiedTime(final long modtime) throws
Exception
- {
+ protected boolean doSetLastModifiedTime(final long modtime) throws
Exception {
file.setLastModified(modtime);
return true;
}
Modified:
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileProvider.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileProvider.java?rev=1808388&r1=1808387&r2=1808388&view=diff
==============================================================================
---
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileProvider.java
(original)
+++
commons/proper/vfs/trunk/commons-vfs2-sandbox/src/main/java/org/apache/commons/vfs2/provider/smb/SmbFileProvider.java
Thu Sep 14 19:43:40 2017
@@ -32,37 +32,19 @@ import org.apache.commons.vfs2.provider.
/**
* A provider for SMB (Samba, Windows share) file systems.
*/
-public class SmbFileProvider
- extends AbstractOriginatingFileProvider
- implements FileProvider
-{
+public class SmbFileProvider extends AbstractOriginatingFileProvider
implements FileProvider {
/** Authentication data supported by this provider. */
- public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES =
new UserAuthenticationData.Type[]
- {
- UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD,
UserAuthenticationData.DOMAIN
- };
+ public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES =
new UserAuthenticationData.Type[] {
+ UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD,
UserAuthenticationData.DOMAIN };
- static final Collection<Capability> capabilities =
- Collections.unmodifiableCollection(Arrays.asList(new Capability[]
- {
- Capability.CREATE,
- Capability.DELETE,
- Capability.RENAME,
- Capability.GET_TYPE,
- Capability.GET_LAST_MODIFIED,
- Capability.SET_LAST_MODIFIED_FILE,
- Capability.SET_LAST_MODIFIED_FOLDER,
- Capability.LIST_CHILDREN,
- Capability.READ_CONTENT,
- Capability.URI,
- Capability.WRITE_CONTENT,
- Capability.APPEND_CONTENT,
- Capability.RANDOM_ACCESS_READ,
- Capability.RANDOM_ACCESS_WRITE
- }));
+ static final Collection<Capability> capabilities = Collections
+ .unmodifiableCollection(Arrays.asList(new Capability[] {
Capability.CREATE, Capability.DELETE,
+ Capability.RENAME, Capability.GET_TYPE,
Capability.GET_LAST_MODIFIED,
+ Capability.SET_LAST_MODIFIED_FILE,
Capability.SET_LAST_MODIFIED_FOLDER, Capability.LIST_CHILDREN,
+ Capability.READ_CONTENT, Capability.URI,
Capability.WRITE_CONTENT, Capability.APPEND_CONTENT,
+ Capability.RANDOM_ACCESS_READ,
Capability.RANDOM_ACCESS_WRITE }));
- public SmbFileProvider()
- {
+ public SmbFileProvider() {
super();
setFileNameParser(SmbFileNameParser.getInstance());
}
@@ -72,13 +54,11 @@ public class SmbFileProvider
*/
@Override
protected FileSystem doCreateFileSystem(final FileName name, final
FileSystemOptions fileSystemOptions)
- throws FileSystemException
- {
+ throws FileSystemException {
return new SmbFileSystem(name, fileSystemOptions);
}
- public Collection<Capability> getCapabilities()
- {
+ public Collection<Capability> getCapabilities() {
return capabilities;
}
}