You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/09/14 19:26:44 UTC
svn commit: r1808381 [16/25] - in /commons/proper/vfs/trunk/commons-vfs2/src:
main/java/org/apache/commons/vfs2/ main/java/org/apache/commons/vfs2/auth/
main/java/org/apache/commons/vfs2/cache/
main/java/org/apache/commons/vfs2/events/ main/java/org/ap...
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java Thu Sep 14 19:26:39 2017
@@ -47,8 +47,7 @@ import com.jcraft.jsch.SftpException;
/**
* An SFTP file.
*/
-public class SftpFileObject extends AbstractFileObject<SftpFileSystem>
-{
+public class SftpFileObject extends AbstractFileObject<SftpFileSystem> {
private static final long MOD_TIME_FACTOR = 1000L;
private SftpATTRS attrs;
@@ -56,18 +55,14 @@ public class SftpFileObject extends Abst
private boolean inRefresh;
- protected SftpFileObject(final AbstractFileName name,
- final SftpFileSystem fileSystem) throws FileSystemException
- {
+ protected SftpFileObject(final AbstractFileName name, final SftpFileSystem fileSystem) throws FileSystemException {
super(name, fileSystem);
- relPath = UriParser.decode(fileSystem.getRootName().getRelativeName(
- name));
+ relPath = UriParser.decode(fileSystem.getRootName().getRelativeName(name));
}
/** @since 2.0 */
@Override
- protected void doDetach() throws Exception
- {
+ protected void doDetach() throws Exception {
attrs = null;
}
@@ -76,55 +71,40 @@ public class SftpFileObject extends Abst
* @since 2.0
*/
@Override
- public void refresh() throws FileSystemException
- {
- if (!inRefresh)
- {
- try
- {
+ public void refresh() throws FileSystemException {
+ if (!inRefresh) {
+ try {
inRefresh = true;
super.refresh();
- try
- {
+ try {
attrs = null;
getType();
- }
- catch (final IOException e)
- {
+ } catch (final IOException e) {
throw new FileSystemException(e);
}
- }
- finally
- {
+ } finally {
inRefresh = false;
}
}
}
/**
- * Determines the type of this file, returns null if the file does not
- * exist.
+ * Determines the type of this file, returns null if the file does not exist.
*/
@Override
- protected FileType doGetType() throws Exception
- {
- if (attrs == null)
- {
+ protected FileType doGetType() throws Exception {
+ if (attrs == null) {
statSelf();
}
- if (attrs == null)
- {
+ if (attrs == null) {
return FileType.IMAGINARY;
}
- if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)
- {
- throw new FileSystemException(
- "vfs.provider.sftp/unknown-permissions.error");
+ if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0) {
+ throw new FileSystemException("vfs.provider.sftp/unknown-permissions.error");
}
- if (attrs.isDir())
- {
+ if (attrs.isDir()) {
return FileType.FOLDER;
}
return FileType.FILE;
@@ -134,8 +114,7 @@ public class SftpFileObject extends Abst
* Called when the type or content of this file changes.
*/
@Override
- protected void onChange() throws Exception
- {
+ protected void onChange() throws Exception {
statSelf();
}
@@ -144,32 +123,22 @@ public class SftpFileObject extends Abst
*
* @throws IOException
*/
- private void statSelf() throws IOException
- {
+ private void statSelf() throws IOException {
ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
setStat(channel.stat(relPath));
- }
- catch (final SftpException e)
- {
- try
- {
+ } catch (final SftpException e) {
+ try {
// maybe the channel has some problems, so recreate the channel and retry
- if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE)
- {
+ if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) {
channel.disconnect();
channel = getAbstractFileSystem().getChannel();
setStat(channel.stat(relPath));
- }
- else
- {
+ } else {
// Really does not exist
attrs = null;
}
- }
- catch (final SftpException innerEx)
- {
+ } catch (final SftpException innerEx) {
// TODO - not strictly true, but jsch 0.1.2 does not give us
// enough info in the exception. Should be using:
// if ( e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE )
@@ -180,9 +149,7 @@ public class SftpFileObject extends Abst
// Does not exist
attrs = null;
}
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
}
@@ -190,8 +157,7 @@ public class SftpFileObject extends Abst
/**
* Set attrs from listChildrenResolved
*/
- private void setStat(final SftpATTRS attrs)
- {
+ private void setStat(final SftpATTRS attrs) {
this.attrs = attrs;
}
@@ -199,58 +165,43 @@ public class SftpFileObject extends Abst
* Creates this file as a folder.
*/
@Override
- protected void doCreateFolder() throws Exception
- {
+ protected void doCreateFolder() throws Exception {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
channel.mkdir(relPath);
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
}
@Override
- protected long doGetLastModifiedTime() throws Exception
- {
- if (attrs == null
- || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0)
- {
- throw new FileSystemException(
- "vfs.provider.sftp/unknown-modtime.error");
+ protected long doGetLastModifiedTime() throws Exception {
+ if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0) {
+ throw new FileSystemException("vfs.provider.sftp/unknown-modtime.error");
}
return attrs.getMTime() * MOD_TIME_FACTOR;
}
/**
- * Sets the last modified time of this file. Is only called if
- * {@link #doGetType} does not return {@link FileType#IMAGINARY}.
+ * Sets the last modified time of this file. Is only called if {@link #doGetType} does not return
+ * {@link FileType#IMAGINARY}.
*
- * @param modtime
- * is modification time in milliseconds. SFTP protocol can send
- * times with nanosecond precision but at the moment jsch send
- * them with second precision.
+ * @param modtime is modification time in milliseconds. SFTP protocol can send times with nanosecond precision but
+ * at the moment jsch send them with second precision.
*/
@Override
- protected boolean doSetLastModifiedTime(final long modtime) throws Exception
- {
+ protected boolean doSetLastModifiedTime(final long modtime) throws Exception {
final int newMTime = (int) (modtime / MOD_TIME_FACTOR);
attrs.setACMODTIME(attrs.getATime(), newMTime);
flushStat();
return true;
}
- private void flushStat() throws IOException, SftpException
- {
+ private void flushStat() throws IOException, SftpException {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
channel.setStat(relPath, attrs);
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
}
@@ -259,22 +210,15 @@ public class SftpFileObject extends Abst
* Deletes the file.
*/
@Override
- protected void doDelete() throws Exception
- {
+ protected void doDelete() throws Exception {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
- if (isFile())
- {
+ try {
+ if (isFile()) {
channel.rm(relPath);
- }
- else
- {
+ } else {
channel.rmdir(relPath);
}
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
}
@@ -283,16 +227,12 @@ public class SftpFileObject extends Abst
* Rename the file.
*/
@Override
- protected void doRename(final FileObject newFile) throws Exception
- {
+ protected void doRename(final FileObject newFile) throws Exception {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
final SftpFileObject newSftpFileObject = (SftpFileObject) FileObjectUtils.getAbstractFileObject(newFile);
channel.rename(relPath, newSftpFileObject.relPath);
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
}
@@ -305,38 +245,31 @@ public class SftpFileObject extends Abst
* @throws Exception If an error occurs
* @since 2.1
*/
- protected PosixPermissions getPermissions(final boolean checkIds) throws Exception
- {
+ protected PosixPermissions getPermissions(final boolean checkIds) throws Exception {
statSelf();
boolean isInGroup = false;
- if (checkIds)
- {
- for (final int groupId : getAbstractFileSystem().getGroupsIds())
- {
- if (groupId == attrs.getGId())
- {
+ if (checkIds) {
+ for (final int groupId : getAbstractFileSystem().getGroupsIds()) {
+ if (groupId == attrs.getGId()) {
isInGroup = true;
break;
}
}
}
- final boolean isOwner = checkIds ? attrs.getUId() == getAbstractFileSystem().getUId() : false;
+ final boolean isOwner = checkIds ? attrs.getUId() == getAbstractFileSystem().getUId() : false;
return new PosixPermissions(attrs.getPermissions(), isOwner, isInGroup);
}
@Override
- protected boolean doIsReadable() throws Exception
- {
+ protected boolean doIsReadable() throws Exception {
return getPermissions(true).isReadable();
}
@Override
- protected boolean doSetReadable(final boolean readable, final boolean ownerOnly) throws Exception
- {
+ protected boolean doSetReadable(final boolean readable, final boolean ownerOnly) throws Exception {
final PosixPermissions permissions = getPermissions(false);
final int newPermissions = permissions.makeReadable(readable, ownerOnly);
- if (newPermissions == permissions.getPermissions())
- {
+ if (newPermissions == permissions.getPermissions()) {
return true;
}
@@ -347,18 +280,15 @@ public class SftpFileObject extends Abst
}
@Override
- protected boolean doIsWriteable() throws Exception
- {
+ protected boolean doIsWriteable() throws Exception {
return getPermissions(true).isWritable();
}
@Override
- protected boolean doSetWritable(final boolean writable, final boolean ownerOnly) throws Exception
- {
+ protected boolean doSetWritable(final boolean writable, final boolean ownerOnly) throws Exception {
final PosixPermissions permissions = getPermissions(false);
final int newPermissions = permissions.makeWritable(writable, ownerOnly);
- if (newPermissions == permissions.getPermissions())
- {
+ if (newPermissions == permissions.getPermissions()) {
return true;
}
@@ -369,19 +299,15 @@ public class SftpFileObject extends Abst
}
@Override
- protected boolean doIsExecutable() throws Exception
- {
+ protected boolean doIsExecutable() throws Exception {
return getPermissions(true).isExecutable();
}
-
@Override
- protected boolean doSetExecutable(final boolean executable, final boolean ownerOnly) throws Exception
- {
+ protected boolean doSetExecutable(final boolean executable, final boolean ownerOnly) throws Exception {
final PosixPermissions permissions = getPermissions(false);
final int newPermissions = permissions.makeExecutable(executable, ownerOnly);
- if (newPermissions == permissions.getPermissions())
- {
+ if (newPermissions == permissions.getPermissions()) {
return true;
}
@@ -395,106 +321,73 @@ public class SftpFileObject extends Abst
* Lists the children of this file.
*/
@Override
- protected FileObject[] doListChildrenResolved() throws Exception
- {
+ protected FileObject[] doListChildrenResolved() throws Exception {
// should not require a round-trip because type is already set.
- if (this.isFile())
- {
+ if (this.isFile()) {
return null;
}
// List the contents of the folder
Vector<?> vector = null;
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
// try the direct way to list the directory on the server to avoid too many roundtrips
vector = channel.ls(relPath);
- }
- catch (final SftpException e)
- {
+ } catch (final SftpException e) {
String workingDirectory = null;
- try
- {
- if (relPath != null)
- {
+ try {
+ if (relPath != null) {
workingDirectory = channel.pwd();
channel.cd(relPath);
}
- }
- catch (final SftpException ex)
- {
+ } catch (final SftpException ex) {
// VFS-210: seems not to be a directory
return null;
}
SftpException lsEx = null;
- try
- {
+ try {
vector = channel.ls(".");
- }
- catch (final SftpException ex)
- {
+ } catch (final SftpException ex) {
lsEx = ex;
- }
- finally
- {
- try
- {
- if (relPath != null)
- {
+ } finally {
+ try {
+ if (relPath != null) {
channel.cd(workingDirectory);
}
- }
- catch (final SftpException xe)
- {
+ } catch (final SftpException xe) {
throw new FileSystemException("vfs.provider.sftp/change-work-directory-back.error",
- workingDirectory, lsEx);
+ workingDirectory, lsEx);
}
}
- if (lsEx != null)
- {
+ if (lsEx != null) {
throw lsEx;
}
- }
- finally
- {
+ } finally {
getAbstractFileSystem().putChannel(channel);
}
- if (vector == null)
- {
- throw new FileSystemException(
- "vfs.provider.sftp/list-children.error");
+ if (vector == null) {
+ throw new FileSystemException("vfs.provider.sftp/list-children.error");
}
// Extract the child names
final ArrayList<FileObject> children = new ArrayList<>();
for (@SuppressWarnings("unchecked") // OK because ChannelSftp.ls() is documented to return Vector<LsEntry>
- final
- Iterator<LsEntry> iterator = (Iterator<LsEntry>) vector.iterator(); iterator.hasNext();)
- {
+ final Iterator<LsEntry> iterator = (Iterator<LsEntry>) vector.iterator(); iterator.hasNext();) {
final LsEntry stat = iterator.next();
String name = stat.getFilename();
- if (VFS.isUriStyle() && stat.getAttrs().isDir()
- && name.charAt(name.length() - 1) != '/')
- {
+ if (VFS.isUriStyle() && stat.getAttrs().isDir() && name.charAt(name.length() - 1) != '/') {
name = name + "/";
}
- if (name.equals(".") || name.equals("..") || name.equals("./")
- || name.equals("../"))
- {
+ if (name.equals(".") || name.equals("..") || name.equals("./") || name.equals("../")) {
continue;
}
- final FileObject fo =
- getFileSystem()
- .resolveFile(
- getFileSystem().getFileSystemManager().resolveName(
- getName(), UriParser.encode(name),
- NameScope.CHILD));
+ final FileObject fo = getFileSystem().resolveFile(getFileSystem().getFileSystemManager()
+ .resolveName(getName(), UriParser.encode(name), NameScope.CHILD));
((SftpFileObject) FileObjectUtils.getAbstractFileObject(fo)).setStat(stat.getAttrs());
@@ -508,8 +401,7 @@ public class SftpFileObject extends Abst
* Lists the children of this file.
*/
@Override
- protected String[] doListChildren() throws Exception
- {
+ protected String[] doListChildren() throws Exception {
// use doListChildrenResolved for performance
return null;
}
@@ -518,40 +410,30 @@ public class SftpFileObject extends Abst
* Returns the size of the file content (in bytes).
*/
@Override
- protected long doGetContentSize() throws Exception
- {
- if (attrs == null
- || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) == 0)
- {
- throw new FileSystemException(
- "vfs.provider.sftp/unknown-size.error");
+ protected long doGetContentSize() throws Exception {
+ if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) == 0) {
+ throw new FileSystemException("vfs.provider.sftp/unknown-size.error");
}
return attrs.getSize();
}
@Override
- protected RandomAccessContent doGetRandomAccessContent(
- final RandomAccessMode mode) throws Exception
- {
+ protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception {
return new SftpRandomAccessContent(this, mode);
}
/**
- * Creates an input stream to read the file content from.
- * The input stream is starting at the given position in the file.
+ * Creates an input stream to read the file content from. The input stream is starting at the given position in the
+ * file.
*/
- InputStream getInputStream(final long filePointer) throws IOException
- {
+ InputStream getInputStream(final long filePointer) throws IOException {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
// Using InputStream directly from the channel
// is much faster than the memory method.
- try
- {
+ try {
final InputStream is = channel.get(getName().getPathDecoded(), null, filePointer);
return new SftpInputStream(channel, is);
- }
- catch (final SftpException e)
- {
+ } catch (final SftpException e) {
getAbstractFileSystem().putChannel(channel);
throw new FileSystemException(e);
}
@@ -561,14 +443,11 @@ public class SftpFileObject extends Abst
* Creates an input stream to read the file content from.
*/
@Override
- protected InputStream doGetInputStream() throws Exception
- {
+ protected InputStream doGetInputStream() throws Exception {
// VFS-113: avoid npe
- synchronized (getAbstractFileSystem())
- {
+ synchronized (getAbstractFileSystem()) {
final ChannelSftp channel = getAbstractFileSystem().getChannel();
- try
- {
+ try {
// return channel.get(getName().getPath());
// hmmm - using the in memory method is soooo much faster ...
@@ -576,28 +455,21 @@ public class SftpFileObject extends Abst
// stream-based methods on ChannelSftp once they work properly
/*
- final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
- channel.get(relPath, outstr);
- outstr.close();
- return new ByteArrayInputStream(outstr.toByteArray());
- */
+ * final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); channel.get(relPath, outstr);
+ * outstr.close(); return new ByteArrayInputStream(outstr.toByteArray());
+ */
InputStream is;
- try
- {
+ try {
// VFS-210: sftp allows to gather an input stream even from a directory and will
// fail on first read. So we need to check the type anyway
- if (!getType().hasContent())
- {
+ if (!getType().hasContent()) {
throw new FileSystemException("vfs.provider/read-not-file.error", getName());
}
is = channel.get(relPath);
- }
- catch (final SftpException e)
- {
- if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
- {
+ } catch (final SftpException e) {
+ if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
throw new FileNotFoundException(getName());
}
@@ -606,10 +478,8 @@ public class SftpFileObject extends Abst
return new SftpInputStream(channel, is);
- }
- finally
- {
-// getAbstractFileSystem().putChannel(channel);
+ } finally {
+ // getAbstractFileSystem().putChannel(channel);
}
}
}
@@ -618,14 +488,12 @@ public class SftpFileObject extends Abst
* 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 {
// TODO - Don't write the entire file into memory. Use the stream-based
// methods on ChannelSftp once the work properly
/*
- final ChannelSftp channel = getAbstractFileSystem().getChannel();
- return new SftpOutputStream(channel);
- */
+ * final ChannelSftp channel = getAbstractFileSystem().getChannel(); return new SftpOutputStream(channel);
+ */
final ChannelSftp channel = getAbstractFileSystem().getChannel();
return new SftpOutputStream(channel, channel.put(relPath));
@@ -634,12 +502,10 @@ public class SftpFileObject extends Abst
/**
* An InputStream that monitors for end-of-file.
*/
- private class SftpInputStream extends MonitorInputStream
- {
+ private class SftpInputStream extends MonitorInputStream {
private final ChannelSftp channel;
- public SftpInputStream(final ChannelSftp channel, final InputStream in)
- {
+ public SftpInputStream(final ChannelSftp channel, final InputStream in) {
super(in);
this.channel = channel;
}
@@ -648,22 +514,18 @@ public class SftpFileObject extends Abst
* Called after the stream has been closed.
*/
@Override
- protected void onClose() throws IOException
- {
+ protected void onClose() throws IOException {
getAbstractFileSystem().putChannel(channel);
}
}
/**
- * An OutputStream that wraps an sftp OutputStream, and closes the channel
- * when the stream is closed.
+ * An OutputStream that wraps an sftp OutputStream, and closes the channel when the stream is closed.
*/
- private class SftpOutputStream extends MonitorOutputStream
- {
+ private class SftpOutputStream extends MonitorOutputStream {
private final ChannelSftp channel;
- public SftpOutputStream(final ChannelSftp channel, final OutputStream out)
- {
+ public SftpOutputStream(final ChannelSftp channel, final OutputStream out) {
super(out);
this.channel = channel;
}
@@ -672,8 +534,7 @@ public class SftpFileObject extends Abst
* Called after this stream is closed.
*/
@Override
- protected void onClose() throws IOException
- {
+ protected void onClose() throws IOException {
getAbstractFileSystem().putChannel(channel);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileProvider.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileProvider.java Thu Sep 14 19:26:39 2017
@@ -36,42 +36,26 @@ import com.jcraft.jsch.Session;
/**
* A provider for accessing files over SFTP.
*/
-public class SftpFileProvider extends AbstractOriginatingFileProvider
-{
+public class SftpFileProvider extends AbstractOriginatingFileProvider {
/** User Information. */
public static final String ATTR_USER_INFO = "UI";
/** Authentication types. */
- public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES =
- new UserAuthenticationData.Type[]
- {
- UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD
- };
+ public static final UserAuthenticationData.Type[] AUTHENTICATOR_TYPES = new UserAuthenticationData.Type[] {
+ UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD };
/** The provider's capabilities. */
- protected static final Collection<Capability> capabilities =
- Collections.unmodifiableCollection(Arrays.asList(new Capability[]
- {
- Capability.CREATE,
- Capability.DELETE,
- Capability.RENAME,
- Capability.GET_TYPE,
- Capability.LIST_CHILDREN,
- Capability.READ_CONTENT,
- Capability.URI,
- Capability.WRITE_CONTENT,
- Capability.GET_LAST_MODIFIED,
- Capability.SET_LAST_MODIFIED_FILE,
- Capability.RANDOM_ACCESS_READ
- }));
+ protected static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays
+ .asList(new Capability[] { Capability.CREATE, Capability.DELETE, Capability.RENAME, Capability.GET_TYPE,
+ Capability.LIST_CHILDREN, Capability.READ_CONTENT, Capability.URI, Capability.WRITE_CONTENT,
+ Capability.GET_LAST_MODIFIED, Capability.SET_LAST_MODIFIED_FILE, Capability.RANDOM_ACCESS_READ }));
// private JSch jSch = new JSch();
/**
* Constructs a new provider.
*/
- public SftpFileProvider()
- {
+ public SftpFileProvider() {
super();
setFileNameParser(SftpFileNameParser.getInstance());
}
@@ -81,8 +65,7 @@ public class SftpFileProvider extends Ab
*/
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
- throws FileSystemException
- {
+ throws FileSystemException {
// JSch jsch = createJSch(fileSystemOptions);
// Create the file system
@@ -90,64 +73,49 @@ public class SftpFileProvider extends Ab
Session session;
UserAuthenticationData authData = null;
- try
- {
+ try {
authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
- session = SftpClientFactory.createConnection(
- rootName.getHostName(),
- rootName.getPort(),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
- UserAuthenticatorUtils.toChar(rootName.getUserName())),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
- UserAuthenticatorUtils.toChar(rootName.getPassword())),
- fileSystemOptions);
- }
- catch (final Exception e)
- {
- throw new FileSystemException("vfs.provider.sftp/connect.error",
- name,
- e);
- }
- finally
- {
+ session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
+ UserAuthenticatorUtils.toChar(rootName.getUserName())),
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
+ UserAuthenticatorUtils.toChar(rootName.getPassword())),
+ fileSystemOptions);
+ } catch (final Exception e) {
+ throw new FileSystemException("vfs.provider.sftp/connect.error", name, e);
+ } finally {
UserAuthenticatorUtils.cleanup(authData);
}
return new SftpFileSystem(rootName, session, fileSystemOptions);
}
-
/**
* Returns the JSch.
*
* @return Returns the jSch.
*/
/*
- private JSch getJSch()
- {
- return this.jSch;
- }
- */
+ * private JSch getJSch() { return this.jSch; }
+ */
/**
* Initializes the component.
+ *
* @throws FileSystemException if an error occurs.
*/
@Override
- public void init() throws FileSystemException
- {
+ public void init() throws FileSystemException {
}
@Override
- public FileSystemConfigBuilder getConfigBuilder()
- {
+ public FileSystemConfigBuilder getConfigBuilder() {
return SftpFileSystemConfigBuilder.getInstance();
}
@Override
- public Collection<Capability> getCapabilities()
- {
+ public Collection<Capability> getCapabilities() {
return capabilities;
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java Thu Sep 14 19:26:39 2017
@@ -39,9 +39,7 @@ import com.jcraft.jsch.SftpException;
/**
* Represents the files on an SFTP server.
*/
-public class SftpFileSystem
- extends AbstractFileSystem
-{
+public class SftpFileSystem extends AbstractFileSystem {
private static final int SLEEP_MILLIS = 100;
private static final int EXEC_BUFFER_SIZE = 128;
@@ -64,25 +62,20 @@ public class SftpFileSystem
*/
private int[] groupsIds;
- protected SftpFileSystem(final GenericFileName rootName,
- final Session session,
- final FileSystemOptions fileSystemOptions)
- {
+ protected SftpFileSystem(final GenericFileName rootName, final Session session,
+ final FileSystemOptions fileSystemOptions) {
super(rootName, null, fileSystemOptions);
this.session = session;
}
@Override
- protected void doCloseCommunicationLink()
- {
- if (idleChannel != null)
- {
+ protected void doCloseCommunicationLink() {
+ if (idleChannel != null) {
idleChannel.disconnect();
idleChannel = null;
}
- if (session != null)
- {
+ if (session != null) {
session.disconnect();
session = null;
}
@@ -95,57 +88,42 @@ public class SftpFileSystem
* @throws FileSystemException if a session cannot be created.
* @throws IOException if an I/O error is detected.
*/
- protected ChannelSftp getChannel() throws IOException
- {
+ protected ChannelSftp getChannel() throws IOException {
ensureSession();
- try
- {
+ try {
// Use the pooled channel, or create a new one
final ChannelSftp channel;
- if (idleChannel != null)
- {
+ if (idleChannel != null) {
channel = idleChannel;
idleChannel = null;
- }
- else
- {
+ } else {
channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
- final Boolean userDirIsRoot =
- SftpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(getFileSystemOptions());
+ final Boolean userDirIsRoot = SftpFileSystemConfigBuilder.getInstance()
+ .getUserDirIsRoot(getFileSystemOptions());
final String workingDirectory = getRootName().getPath();
- if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
- {
- try
- {
+ if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue())) {
+ try {
channel.cd(workingDirectory);
- }
- catch (final SftpException e)
- {
- throw new FileSystemException("vfs.provider.sftp/change-work-directory.error",
- workingDirectory, e);
+ } catch (final SftpException e) {
+ throw new FileSystemException("vfs.provider.sftp/change-work-directory.error", workingDirectory,
+ e);
}
}
}
- final String fileNameEncoding = SftpFileSystemConfigBuilder.getInstance().getFileNameEncoding(
- getFileSystemOptions());
+ final String fileNameEncoding = SftpFileSystemConfigBuilder.getInstance()
+ .getFileNameEncoding(getFileSystemOptions());
- if (fileNameEncoding != null)
- {
- try
- {
+ if (fileNameEncoding != null) {
+ try {
channel.setFilenameEncoding(fileNameEncoding);
- }
- catch (final SftpException e)
- {
+ } catch (final SftpException e) {
throw new FileSystemException("vfs.provider.sftp/filename-encoding.error", fileNameEncoding);
}
}
return channel;
- }
- catch (final JSchException e)
- {
+ } catch (final JSchException e) {
throw new FileSystemException("vfs.provider.sftp/connect.error", getRootName(), e);
}
}
@@ -155,37 +133,28 @@ public class SftpFileSystem
*
* @throws FileSystemException if a session cannot be created.
*/
- private void ensureSession() throws FileSystemException
- {
- if (this.session == null || !this.session.isConnected())
- {
+ private void ensureSession() throws FileSystemException {
+ if (this.session == null || !this.session.isConnected()) {
doCloseCommunicationLink();
// channel closed. e.g. by freeUnusedResources, but now we need it again
Session session;
UserAuthenticationData authData = null;
- try
- {
+ try {
final GenericFileName rootName = (GenericFileName) getRootName();
authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(),
SftpFileProvider.AUTHENTICATOR_TYPES);
- session = SftpClientFactory.createConnection(
- rootName.getHostName(),
- rootName.getPort(),
+ session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(),
UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME,
UserAuthenticatorUtils.toChar(rootName.getUserName())),
UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD,
UserAuthenticatorUtils.toChar(rootName.getPassword())),
getFileSystemOptions());
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
throw new FileSystemException("vfs.provider.sftp/connect.error", getRootName(), e);
- }
- finally
- {
+ } finally {
UserAuthenticatorUtils.cleanup(authData);
}
this.session = session;
@@ -197,18 +166,13 @@ public class SftpFileSystem
*
* @param channel the used channel.
*/
- protected void putChannel(final ChannelSftp channel)
- {
- if (idleChannel == null)
- {
+ protected void putChannel(final ChannelSftp channel) {
+ if (idleChannel == null) {
// put back the channel only if it is still connected
- if (channel.isConnected() && !channel.isClosed())
- {
+ if (channel.isConnected() && !channel.isClosed()) {
idleChannel = channel;
}
- }
- else
- {
+ } else {
channel.disconnect();
}
}
@@ -217,19 +181,15 @@ public class SftpFileSystem
* Adds the capabilities of this file system.
*/
@Override
- protected void addCapabilities(final Collection<Capability> caps)
- {
+ protected void addCapabilities(final Collection<Capability> caps) {
caps.addAll(SftpFileProvider.capabilities);
}
/**
- * Creates a file object. This method is called only if the requested
- * file is not cached.
+ * Creates a file object. This method is called only if the requested file is not cached.
*/
@Override
- protected FileObject createFile(final AbstractFileName name)
- throws FileSystemException
- {
+ protected FileObject createFile(final AbstractFileName name) throws FileSystemException {
return new SftpFileObject(name, this);
}
@@ -239,8 +199,7 @@ public class SftpFileSystem
* @return 1000
*/
@Override
- public double getLastModTimeAccuracy()
- {
+ public double getLastModTimeAccuracy() {
return LAST_MOD_TIME_ACCURACY;
}
@@ -252,14 +211,11 @@ public class SftpFileSystem
* @throws IOException if an I/O error is detected.
* @since 2.1
*/
- public int[] getGroupsIds() throws JSchException, IOException
- {
- if (groupsIds == null)
- {
+ public int[] getGroupsIds() throws JSchException, IOException {
+ if (groupsIds == null) {
final StringBuilder output = new StringBuilder();
final int code = executeCommand("id -G", output);
- if (code != 0)
- {
+ if (code != 0) {
throw new JSchException("Could not get the groups id of the current user (error code: " + code + ")");
}
@@ -267,8 +223,7 @@ public class SftpFileSystem
final String[] groups = output.toString().trim().split("\\s+");
final int[] groupsIds = new int[groups.length];
- for (int i = 0; i < groups.length; i++)
- {
+ for (int i = 0; i < groups.length; i++) {
groupsIds[i] = Integer.parseInt(groups[i]);
}
@@ -285,16 +240,13 @@ public class SftpFileSystem
* @throws IOException if an I/O error is detected.
* @since 2.1
*/
- public int getUId() throws JSchException, IOException
- {
- if (uid < 0)
- {
+ public int getUId() throws JSchException, IOException {
+ if (uid < 0) {
final StringBuilder output = new StringBuilder();
final int code = executeCommand("id -u", output);
- if (code != 0)
- {
- throw new FileSystemException("Could not get the user id of the current user (error code: " + code
- + ")");
+ if (code != 0) {
+ throw new FileSystemException(
+ "Could not get the user id of the current user (error code: " + code + ")");
}
uid = Integer.parseInt(output.toString().trim());
}
@@ -311,15 +263,13 @@ public class SftpFileSystem
* @throws FileSystemException if a session cannot be created.
* @throws IOException if an I/O error is detected.
*/
- private int executeCommand(final String command, final StringBuilder output) throws JSchException, IOException
- {
+ private int executeCommand(final String command, final StringBuilder output) throws JSchException, IOException {
ensureSession();
final ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
channel.setInputStream(null);
- try (final InputStreamReader stream = new InputStreamReader(channel.getInputStream()))
- {
+ try (final InputStreamReader stream = new InputStreamReader(channel.getInputStream())) {
channel.setErrStream(System.err, true);
channel.connect();
@@ -332,14 +282,10 @@ public class SftpFileSystem
}
// Wait until the command finishes (should not be long since we read the output stream)
- while (!channel.isClosed())
- {
- try
- {
+ while (!channel.isClosed()) {
+ try {
Thread.sleep(SLEEP_MILLIS);
- }
- catch (final Exception ee)
- {
+ } catch (final Exception ee) {
// TODO: swallow exception, really?
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java Thu Sep 14 19:26:39 2017
@@ -29,13 +29,11 @@ import com.jcraft.jsch.UserInfo;
/**
* The config builder for various SFTP configuration options.
*/
-public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder
-{
+public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
/**
* Proxy type.
*/
- public static final class ProxyType implements Serializable, Comparable<ProxyType>
- {
+ public static final class ProxyType implements Serializable, Comparable<ProxyType> {
/**
* serialVersionUID format is YYYYMMDD for the date of the last binary change.
*/
@@ -43,33 +41,27 @@ public final class SftpFileSystemConfigB
private final String proxyType;
- private ProxyType(final String proxyType)
- {
+ private ProxyType(final String proxyType) {
this.proxyType = proxyType;
}
@Override
- public int compareTo(final ProxyType pType)
- {
+ public int compareTo(final ProxyType pType) {
return this.proxyType.compareTo(pType.proxyType);
}
@Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
+ public boolean equals(final Object obj) {
+ if (this == obj) {
return true;
}
- if (obj == null || this.getClass() != obj.getClass())
- {
+ if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
final ProxyType pType = (ProxyType) obj;
- if (this.proxyType != null ? !this.proxyType.equals(pType.proxyType) : pType.proxyType != null)
- {
+ if (this.proxyType != null ? !this.proxyType.equals(pType.proxyType) : pType.proxyType != null) {
return false;
}
@@ -81,8 +73,7 @@ public final class SftpFileSystemConfigB
* @since 2.0
*/
@Override
- public int hashCode()
- {
+ public int hashCode() {
return this.proxyType.hashCode();
}
}
@@ -96,16 +87,13 @@ public final class SftpFileSystemConfigB
/**
* Connects to the SFTP server through a remote host reached by SSH.
* <p>
- * On this proxy host, a command
- * (e.g. {@linkplain SftpStreamProxy#NETCAT_COMMAND}
- * or {@linkplain SftpStreamProxy#NETCAT_COMMAND}) is run to forward
- * input/output streams between the target host and the VFS host.
- * <p>
- * When used, the proxy username ({@linkplain #setProxyUser}) and
- * hostname ({@linkplain #setProxyHost}) <b>must</b> be set.
- * Optionnaly, the command ({@linkplain #setProxyCommand}),
- * password ({@linkplain #setProxyPassword}) and connection options
- * ({@linkplain #setProxyOptions}) can be set.
+ * On this proxy host, a command (e.g. {@linkplain SftpStreamProxy#NETCAT_COMMAND} or
+ * {@linkplain SftpStreamProxy#NETCAT_COMMAND}) is run to forward input/output streams between the target host and
+ * the VFS host.
+ * <p>
+ * When used, the proxy username ({@linkplain #setProxyUser}) and hostname ({@linkplain #setProxyHost}) <b>must</b>
+ * be set. Optionnaly, the command ({@linkplain #setProxyCommand}), password ({@linkplain #setProxyPassword}) and
+ * connection options ({@linkplain #setProxyOptions}) can be set.
*/
public static final ProxyType PROXY_STREAM = new ProxyType("stream");
@@ -133,8 +121,7 @@ public final class SftpFileSystemConfigB
private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT";
private static final String ENCODING = _PREFIX + ".ENCODING";
- private SftpFileSystemConfigBuilder()
- {
+ private SftpFileSystemConfigBuilder() {
super("sftp.");
}
@@ -143,37 +130,31 @@ public final class SftpFileSystemConfigB
*
* @return the singleton builder.
*/
- public static SftpFileSystemConfigBuilder getInstance()
- {
+ public static SftpFileSystemConfigBuilder getInstance() {
return BUILDER;
}
/**
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return The names of the compression algorithms, comma-separated.
* @see #setCompression
*/
- public String getCompression(final FileSystemOptions opts)
- {
+ public String getCompression(final FileSystemOptions opts) {
return this.getString(opts, COMPRESSION);
}
@Override
- protected Class<? extends FileSystem> getConfigClass()
- {
+ protected Class<? extends FileSystem> getConfigClass() {
return SftpFileSystem.class;
}
/**
* Gets the file name encoding.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return the file name encoding
*/
- public String getFileNameEncoding(final FileSystemOptions opts)
- {
+ public String getFileNameEncoding(final FileSystemOptions opts) {
return this.getString(opts, ENCODING);
}
@@ -188,14 +169,11 @@ public final class SftpFileSystemConfigB
* @deprecated As of 2.1 use {@link #getIdentityInfo(FileSystemOptions)}
*/
@Deprecated
- public File[] getIdentities(final FileSystemOptions opts)
- {
+ public File[] getIdentities(final FileSystemOptions opts) {
final IdentityInfo[] info = getIdentityInfo(opts);
- if (info != null)
- {
+ if (info != null) {
final File[] files = new File[info.length];
- for (int i = 0; i < files.length; ++i)
- {
+ for (int i = 0; i < files.length; ++i) {
files[i] = info[i].getPrivateKey();
}
return files;
@@ -206,174 +184,145 @@ public final class SftpFileSystemConfigB
/**
* Gets the identity info.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return the array of identity info instances.
* @see #setIdentityInfo
*/
- public IdentityInfo[] getIdentityInfo(final FileSystemOptions opts)
- {
+ public IdentityInfo[] getIdentityInfo(final FileSystemOptions opts) {
return (IdentityInfo[]) this.getParam(opts, IDENTITIES);
}
/**
* Get the identity repository factory.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return the IdentityRepositoryFactory
*/
- public IdentityRepositoryFactory getIdentityRepositoryFactory(final FileSystemOptions opts)
- {
+ public IdentityRepositoryFactory getIdentityRepositoryFactory(final FileSystemOptions opts) {
return (IdentityRepositoryFactory) this.getParam(opts, IDENTITY_REPOSITORY_FACTORY);
}
/**
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return the known hosts File.
* @see #setKnownHosts
*/
- public File getKnownHosts(final FileSystemOptions opts)
- {
+ public File getKnownHosts(final FileSystemOptions opts) {
return (File) this.getParam(opts, KNOWN_HOSTS);
}
/**
* Gets authentication order.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return The authentication order.
* @since 2.0
*/
- public String getPreferredAuthentications(final FileSystemOptions opts)
- {
+ public String getPreferredAuthentications(final FileSystemOptions opts) {
return getString(opts, PREFERRED_AUTHENTICATIONS);
}
/**
- * Gets the command that will be run on the proxy
- * host when using a {@linkplain SftpStreamProxy}. The
- * command defaults to {@linkplain SftpStreamProxy#NETCAT_COMMAND}.
+ * Gets the command that will be run on the proxy host when using a {@linkplain SftpStreamProxy}. The command
+ * defaults to {@linkplain SftpStreamProxy#NETCAT_COMMAND}.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyOptions
* @see SftpStreamProxy
* @see #setProxyOptions
* @since 2.1
*/
- public String getProxyCommand(final FileSystemOptions opts)
- {
+ public String getProxyCommand(final FileSystemOptions opts) {
return this.getString(opts, PROXY_COMMAND, SftpStreamProxy.NETCAT_COMMAND);
}
/**
* Gets the proxy to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyHost
* @see #getProxyPort
* @see #setProxyHost
*/
- public String getProxyHost(final FileSystemOptions opts)
- {
+ public String getProxyHost(final FileSystemOptions opts) {
return this.getString(opts, PROXY_HOST);
}
/**
- * Gets the proxy options that are used to connect
- * to the proxy host.
+ * Gets the proxy options that are used to connect to the proxy host.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyOptions
* @see SftpStreamProxy
* @see #setProxyOptions
* @since 2.1
*/
- public FileSystemOptions getProxyOptions(final FileSystemOptions opts)
- {
+ public FileSystemOptions getProxyOptions(final FileSystemOptions opts) {
return (FileSystemOptions) this.getParam(opts, PROXY_OPTIONS);
}
/**
- * Gets the proxy password that are used to connect
- * to the proxy host.
+ * Gets the proxy password that are used to connect to the proxy host.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyOptions
* @see SftpStreamProxy
* @see #setProxyPassword
* @since 2.1
*/
- public String getProxyPassword(final FileSystemOptions opts)
- {
+ public String getProxyPassword(final FileSystemOptions opts) {
return this.getString(opts, PROXY_PASSWORD);
}
/**
* Gets the proxy-port to use for the SFTP the connection.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyPort: the port number or 0 if it is not set
* @see #setProxyPort
* @see #getProxyHost
*/
- public int getProxyPort(final FileSystemOptions opts)
- {
+ public int getProxyPort(final FileSystemOptions opts) {
return this.getInteger(opts, PROXY_PORT, 0);
}
/**
* Gets the proxy type to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return The ProxyType.
*/
- public ProxyType getProxyType(final FileSystemOptions opts)
- {
+ public ProxyType getProxyType(final FileSystemOptions opts) {
return (ProxyType) this.getParam(opts, PROXY_TYPE);
}
/**
* Gets the user name for the proxy used for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return proxyUser
* @see #setProxyUser
* @since 2.1
*/
- public String getProxyUser(final FileSystemOptions opts)
- {
+ public String getProxyUser(final FileSystemOptions opts) {
return this.getString(opts, PROXY_USER);
}
/**
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return the option value The host key checking.
* @see #setStrictHostKeyChecking(FileSystemOptions, String)
*/
- public String getStrictHostKeyChecking(final FileSystemOptions opts)
- {
+ public String getStrictHostKeyChecking(final FileSystemOptions opts) {
return this.getString(opts, STRICT_HOST_KEY_CHECKING, HOST_KEY_CHECK_NO);
}
/**
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return The timeout value in milliseconds.
* @see #setTimeout
*/
- public Integer getTimeout(final FileSystemOptions opts)
- {
+ public Integer getTimeout(final FileSystemOptions opts) {
return this.getInteger(opts, TIMEOUT);
}
@@ -382,24 +331,20 @@ public final class SftpFileSystemConfigB
* <code>Boolean.TRUE</code> if the method {@link #setUserDirIsRoot(FileSystemOptions, boolean)} has not been
* invoked.
*
- * @param opts
- * The FileSystemOptions.
+ * @param opts The FileSystemOptions.
* @return <code>Boolean.TRUE</code> if VFS treats the user directory as the root directory.
* @see #setUserDirIsRoot
*/
- public Boolean getUserDirIsRoot(final FileSystemOptions opts)
- {
+ public Boolean getUserDirIsRoot(final FileSystemOptions opts) {
return this.getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
}
/**
- * @param opts
- * The FileSystem options.
+ * @param opts The FileSystem options.
* @return The UserInfo.
* @see #setUserInfo
*/
- public UserInfo getUserInfo(final FileSystemOptions opts)
- {
+ public UserInfo getUserInfo(final FileSystemOptions opts) {
return (UserInfo) this.getParam(opts, UserInfo.class.getName());
}
@@ -410,15 +355,11 @@ public final class SftpFileSystemConfigB
* <p>
* See the Jsch documentation (in particular the README file) for details.
*
- * @param opts
- * The FileSystem options.
- * @param compression
- * The names of the compression algorithms, comma-separated.
- * @throws FileSystemException
- * if an error occurs.
+ * @param opts The FileSystem options.
+ * @param compression The names of the compression algorithms, comma-separated.
+ * @throws FileSystemException if an error occurs.
*/
- public void setCompression(final FileSystemOptions opts, final String compression) throws FileSystemException
- {
+ public void setCompression(final FileSystemOptions opts, final String compression) throws FileSystemException {
this.setParam(opts, COMPRESSION, compression);
}
@@ -428,8 +369,7 @@ public final class SftpFileSystemConfigB
* @param opts The FileSystem options.
* @param fileNameEncoding The name of the encoding to use for file names.
*/
- public void setFileNameEncoding(final FileSystemOptions opts, final String fileNameEncoding)
- {
+ public void setFileNameEncoding(final FileSystemOptions opts, final String fileNameEncoding) {
this.setParam(opts, ENCODING, fileNameEncoding);
}
@@ -444,15 +384,11 @@ public final class SftpFileSystemConfigB
* @deprecated As of 2.1 use {@link #setIdentityInfo(FileSystemOptions, IdentityInfo...)}
*/
@Deprecated
- public void setIdentities(final FileSystemOptions opts, final File... identityFiles)
- throws FileSystemException
- {
+ public void setIdentities(final FileSystemOptions opts, final File... identityFiles) throws FileSystemException {
IdentityInfo[] info = null;
- if (identityFiles != null)
- {
+ if (identityFiles != null) {
info = new IdentityInfo[identityFiles.length];
- for (int i = 0; i < identityFiles.length; i++)
- {
+ for (int i = 0; i < identityFiles.length; i++) {
info[i] = new IdentityInfo(identityFiles[i]);
}
}
@@ -462,17 +398,13 @@ public final class SftpFileSystemConfigB
/**
* Sets the identity info (your private key files).
*
- * @param opts
- * The FileSystem options.
- * @param identites
- * An array of identity info.
- * @throws FileSystemException
- * if an error occurs.
+ * @param opts The FileSystem options.
+ * @param identites An array of identity info.
+ * @throws FileSystemException if an error occurs.
* @since 2.1
*/
public void setIdentityInfo(final FileSystemOptions opts, final IdentityInfo... identites)
- throws FileSystemException
- {
+ throws FileSystemException {
this.setParam(opts, IDENTITIES, identites);
}
@@ -481,17 +413,13 @@ public final class SftpFileSystemConfigB
* <p>
* This is useful when you want to use e.g. an SSH agent as provided.
*
- * @param opts
- * The FileSystem options.
- * @param factory
- * An identity repository.
- * @throws FileSystemException
- * if an error occurs.
+ * @param opts The FileSystem options.
+ * @param factory An identity repository.
+ * @throws FileSystemException if an error occurs.
* @see <a href="http://www.jcraft.com/jsch-agent-proxy/">JSch agent proxy</a>
*/
public void setIdentityRepositoryFactory(final FileSystemOptions opts, final IdentityRepositoryFactory factory)
- throws FileSystemException
- {
+ throws FileSystemException {
this.setParam(opts, IDENTITY_REPOSITORY_FACTORY, factory);
}
@@ -500,44 +428,34 @@ public final class SftpFileSystemConfigB
* <p>
* We use {@link java.io.File} because JSch cannot deal with VFS FileObjects.
*
- * @param opts
- * The FileSystem options.
- * @param knownHosts
- * The known hosts file.
- * @throws FileSystemException
- * if an error occurs.
+ * @param opts The FileSystem options.
+ * @param knownHosts The known hosts file.
+ * @throws FileSystemException if an error occurs.
*/
- public void setKnownHosts(final FileSystemOptions opts, final File knownHosts) throws FileSystemException
- {
+ public void setKnownHosts(final FileSystemOptions opts, final File knownHosts) throws FileSystemException {
this.setParam(opts, KNOWN_HOSTS, knownHosts);
}
/**
* Configures authentication order.
*
- * @param opts
- * The FileSystem options.
- * @param preferredAuthentications
- * The authentication order.
+ * @param opts The FileSystem options.
+ * @param preferredAuthentications The authentication order.
* @since 2.0
*/
- public void setPreferredAuthentications(final FileSystemOptions opts, final String preferredAuthentications)
- {
+ public void setPreferredAuthentications(final FileSystemOptions opts, final String preferredAuthentications) {
this.setParam(opts, PREFERRED_AUTHENTICATIONS, preferredAuthentications);
}
/**
* Sets the proxy username to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
- * @param proxyCommand
- * the port
+ * @param opts The FileSystem options.
+ * @param proxyCommand the port
* @see #getProxyOptions
* @since 2.1
*/
- public void setProxyCommand(final FileSystemOptions opts, final String proxyCommand)
- {
+ public void setProxyCommand(final FileSystemOptions opts, final String proxyCommand) {
this.setParam(opts, PROXY_COMMAND, proxyCommand);
}
@@ -546,44 +464,35 @@ public final class SftpFileSystemConfigB
*
* You MUST also set the proxy port to use the proxy.
*
- * @param opts
- * The FileSystem options.
- * @param proxyHost
- * the host
+ * @param opts The FileSystem options.
+ * @param proxyHost the host
* @see #setProxyPort
*/
- public void setProxyHost(final FileSystemOptions opts, final String proxyHost)
- {
+ public void setProxyHost(final FileSystemOptions opts, final String proxyHost) {
this.setParam(opts, PROXY_HOST, proxyHost);
}
/**
* Sets the proxy username to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
- * @param proxyOptions
- * the options
+ * @param opts The FileSystem options.
+ * @param proxyOptions the options
* @see #getProxyOptions
* @since 2.1
*/
- public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions)
- {
+ public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions) {
this.setParam(opts, PROXY_OPTIONS, proxyOptions);
}
/**
* Sets the proxy password to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
- * @param proxyPassword
- * the username used to connect to the proxy
+ * @param opts The FileSystem options.
+ * @param proxyPassword the username used to connect to the proxy
* @see #getProxyPassword
* @since 2.1
*/
- public void setProxyPassword(final FileSystemOptions opts, final String proxyPassword)
- {
+ public void setProxyPassword(final FileSystemOptions opts, final String proxyPassword) {
this.setParam(opts, PROXY_PASSWORD, proxyPassword);
}
@@ -592,14 +501,11 @@ public final class SftpFileSystemConfigB
* <p>
* You MUST also set the proxy host to use the proxy.
*
- * @param opts
- * The FileSystem options.
- * @param proxyPort
- * the port
+ * @param opts The FileSystem options.
+ * @param proxyPort the port
* @see #setProxyHost
*/
- public void setProxyPort(final FileSystemOptions opts, final int proxyPort)
- {
+ public void setProxyPort(final FileSystemOptions opts, final int proxyPort) {
this.setParam(opts, PROXY_PORT, Integer.valueOf(proxyPort));
}
@@ -613,28 +519,22 @@ public final class SftpFileSystemConfigB
* <li>{@linkplain #PROXY_STREAM} connects through a remote host stream command</li>
* </ul>
*
- * @param opts
- * The FileSystem options.
- * @param proxyType
- * the type of the proxy to use.
+ * @param opts The FileSystem options.
+ * @param proxyType the type of the proxy to use.
*/
- public void setProxyType(final FileSystemOptions opts, final ProxyType proxyType)
- {
+ public void setProxyType(final FileSystemOptions opts, final ProxyType proxyType) {
this.setParam(opts, PROXY_TYPE, proxyType);
}
/**
* Sets the proxy username to use for the SFTP connection.
*
- * @param opts
- * The FileSystem options.
- * @param proxyUser
- * the username used to connect to the proxy
+ * @param opts The FileSystem options.
+ * @param proxyUser the username used to connect to the proxy
* @see #getProxyUser
* @since 2.1
*/
- public void setProxyUser(final FileSystemOptions opts, final String proxyUser)
- {
+ public void setProxyUser(final FileSystemOptions opts, final String proxyUser) {
this.setParam(opts, PROXY_USER, proxyUser);
}
@@ -647,20 +547,14 @@ public final class SftpFileSystemConfigB
* See the jsch documentation for details.
* </p>
*
- * @param opts
- * The FileSystem options.
- * @param hostKeyChecking
- * The host key checking to use.
- * @throws FileSystemException
- * if an error occurs.
+ * @param opts The FileSystem options.
+ * @param hostKeyChecking The host key checking to use.
+ * @throws FileSystemException if an error occurs.
*/
public void setStrictHostKeyChecking(final FileSystemOptions opts, final String hostKeyChecking)
- throws FileSystemException
- {
- if (hostKeyChecking == null
- || (!hostKeyChecking.equals(HOST_KEY_CHECK_ASK) && !hostKeyChecking.equals(HOST_KEY_CHECK_NO) &&
- !hostKeyChecking.equals(HOST_KEY_CHECK_YES)))
- {
+ throws FileSystemException {
+ if (hostKeyChecking == null || (!hostKeyChecking.equals(HOST_KEY_CHECK_ASK)
+ && !hostKeyChecking.equals(HOST_KEY_CHECK_NO) && !hostKeyChecking.equals(HOST_KEY_CHECK_YES))) {
throw new FileSystemException("vfs.provider.sftp/StrictHostKeyChecking-arg.error", hostKeyChecking);
}
@@ -670,39 +564,30 @@ public final class SftpFileSystemConfigB
/**
* Sets the timeout value on Jsch session.
*
- * @param opts
- * The FileSystem options.
- * @param timeout
- * The timeout in milliseconds.
+ * @param opts The FileSystem options.
+ * @param timeout The timeout in milliseconds.
*/
- public void setTimeout(final FileSystemOptions opts, final Integer timeout)
- {
+ public void setTimeout(final FileSystemOptions opts, final Integer timeout) {
this.setParam(opts, TIMEOUT, timeout);
}
/**
* Sets the whether to use the user directory as root (do not change to file system root).
*
- * @param opts
- * The FileSystem options.
- * @param userDirIsRoot
- * true if the user directory is the root directory.
+ * @param opts The FileSystem options.
+ * @param userDirIsRoot true if the user directory is the root directory.
*/
- public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot)
- {
+ public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot) {
this.setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE : Boolean.FALSE);
}
/**
* Sets the Jsch UserInfo class to use.
*
- * @param opts
- * The FileSystem options.
- * @param info
- * User information.
+ * @param opts The FileSystem options.
+ * @param info User information.
*/
- public void setUserInfo(final FileSystemOptions opts, final UserInfo info)
- {
+ public void setUserInfo(final FileSystemOptions opts, final UserInfo info) {
this.setParam(opts, UserInfo.class.getName(), info);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpRandomAccessContent.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpRandomAccessContent.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpRandomAccessContent.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpRandomAccessContent.java Thu Sep 14 19:26:39 2017
@@ -28,8 +28,7 @@ import org.apache.commons.vfs2.util.Rand
/**
* Random access content.
*/
-class SftpRandomAccessContent extends AbstractRandomAccessStreamContent
-{
+class SftpRandomAccessContent extends AbstractRandomAccessStreamContent {
/** file pointer */
protected long filePointer = 0;
@@ -37,8 +36,7 @@ class SftpRandomAccessContent extends Ab
private DataInputStream dis = null;
private InputStream mis = null;
- SftpRandomAccessContent(final SftpFileObject fileObject, final RandomAccessMode mode)
- {
+ SftpRandomAccessContent(final SftpFileObject fileObject, final RandomAccessMode mode) {
super(mode);
this.fileObject = fileObject;
@@ -46,27 +44,21 @@ class SftpRandomAccessContent extends Ab
}
@Override
- public long getFilePointer() throws IOException
- {
+ public long getFilePointer() throws IOException {
return filePointer;
}
@Override
- public void seek(final long pos) throws IOException
- {
- if (pos == filePointer)
- {
+ public void seek(final long pos) throws IOException {
+ if (pos == filePointer) {
// no change
return;
}
- if (pos < 0)
- {
- throw new FileSystemException("vfs.provider/random-access-invalid-position.error",
- Long.valueOf(pos));
+ if (pos < 0) {
+ throw new FileSystemException("vfs.provider/random-access-invalid-position.error", Long.valueOf(pos));
}
- if (dis != null)
- {
+ if (dis != null) {
close();
}
@@ -74,53 +66,43 @@ class SftpRandomAccessContent extends Ab
}
@Override
- protected DataInputStream getDataInputStream() throws IOException
- {
- if (dis != null)
- {
+ protected DataInputStream getDataInputStream() throws IOException {
+ if (dis != null) {
return dis;
}
// FtpClient client = fileSystem.getClient();
mis = fileObject.getInputStream(filePointer);
- dis = new DataInputStream(new FilterInputStream(mis)
- {
+ dis = new DataInputStream(new FilterInputStream(mis) {
@Override
- public int read() throws IOException
- {
+ public int read() throws IOException {
final int ret = super.read();
- if (ret > -1)
- {
+ if (ret > -1) {
filePointer++;
}
return ret;
}
@Override
- public int read(final byte[] b) throws IOException
- {
+ public int read(final byte[] b) throws IOException {
final int ret = super.read(b);
- if (ret > -1)
- {
+ if (ret > -1) {
filePointer += ret;
}
return ret;
}
@Override
- public int read(final byte[] b, final int off, final int len) throws IOException
- {
+ public int read(final byte[] b, final int off, final int len) throws IOException {
final int ret = super.read(b, off, len);
- if (ret > -1)
- {
+ if (ret > -1) {
filePointer += ret;
}
return ret;
}
@Override
- public void close() throws IOException
- {
+ public void close() throws IOException {
SftpRandomAccessContent.this.close();
}
});
@@ -128,12 +110,9 @@ class SftpRandomAccessContent extends Ab
return dis;
}
-
@Override
- public void close() throws IOException
- {
- if (dis != null)
- {
+ public void close() throws IOException {
+ if (dis != null) {
// mis.abort();
mis.close();
@@ -146,8 +125,7 @@ class SftpRandomAccessContent extends Ab
}
@Override
- public long length() throws IOException
- {
+ public long length() throws IOException {
return fileObject.getContent().getSize();
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpStreamProxy.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpStreamProxy.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpStreamProxy.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpStreamProxy.java Thu Sep 14 19:26:39 2017
@@ -38,8 +38,7 @@ import com.jcraft.jsch.SocketFactory;
*
* @since 2.1
*/
-public class SftpStreamProxy implements Proxy
-{
+public class SftpStreamProxy implements Proxy {
/**
* Command format using bash built-in TCP stream.
*/
@@ -100,24 +99,17 @@ public class SftpStreamProxy implements
/**
* Creates a stream proxy.
*
- * @param commandFormat
- * A format string that will be used to create the command to execute on the proxy host using
+ * @param commandFormat A format string that will be used to create the command to execute on the proxy host using
* {@linkplain String#format(String, Object...)}. Two parameters are given to the format command, the
* target host name (String) and port (Integer).
- * @param proxyUser
- * The proxy user
- * @param proxyPassword
- * The proxy password
- * @param proxyHost
- * The proxy host
- * @param proxyPort
- * The port to connect to on the proxy
- * @param proxyOptions
- * Options used when connecting to the proxy
+ * @param proxyUser The proxy user
+ * @param proxyPassword The proxy password
+ * @param proxyHost The proxy host
+ * @param proxyPort The port to connect to on the proxy
+ * @param proxyOptions Options used when connecting to the proxy
*/
public SftpStreamProxy(final String commandFormat, final String proxyUser, final String proxyHost,
- final int proxyPort, final String proxyPassword, final FileSystemOptions proxyOptions)
- {
+ final int proxyPort, final String proxyPassword, final FileSystemOptions proxyOptions) {
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.proxyUser = proxyUser;
@@ -127,23 +119,18 @@ public class SftpStreamProxy implements
}
@Override
- public void close()
- {
- if (channel != null)
- {
+ public void close() {
+ if (channel != null) {
channel.disconnect();
}
- if (session != null)
- {
+ if (session != null) {
session.disconnect();
}
}
@Override
- public void connect(final SocketFactory socketFactory, final String targetHost,
- final int targetPort, final int timeout)
- throws Exception
- {
+ public void connect(final SocketFactory socketFactory, final String targetHost, final int targetPort,
+ final int timeout) throws Exception {
session = SftpClientFactory.createConnection(proxyHost, proxyPort, proxyUser.toCharArray(),
proxyPassword.toCharArray(), proxyOptions);
channel = (ChannelExec) session.openChannel("exec");
@@ -152,34 +139,25 @@ public class SftpStreamProxy implements
}
@Override
- public InputStream getInputStream()
- {
- try
- {
+ public InputStream getInputStream() {
+ try {
return channel.getInputStream();
- }
- catch (final IOException e)
- {
+ } catch (final IOException e) {
throw new IllegalStateException("IOException getting the SSH proxy input stream", e);
}
}
@Override
- public OutputStream getOutputStream()
- {
- try
- {
+ public OutputStream getOutputStream() {
+ try {
return channel.getOutputStream();
- }
- catch (final IOException e)
- {
+ } catch (final IOException e) {
throw new IllegalStateException("IOException getting the SSH proxy output stream", e);
}
}
@Override
- public Socket getSocket()
- {
+ public Socket getSocket() {
return null;
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/TrustEveryoneUserInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/TrustEveryoneUserInfo.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/TrustEveryoneUserInfo.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/TrustEveryoneUserInfo.java Thu Sep 14 19:26:39 2017
@@ -24,39 +24,33 @@ import com.jcraft.jsch.UserInfo;
/**
* Helper class to trust a new host.
*/
-public class TrustEveryoneUserInfo implements UserInfo
-{
+public class TrustEveryoneUserInfo implements UserInfo {
private static final Log log = LogFactory.getLog(TrustEveryoneUserInfo.class);
@Override
- public String getPassphrase()
- {
+ public String getPassphrase() {
return null;
}
@Override
- public String getPassword()
- {
+ public String getPassword() {
return null;
}
@Override
- public boolean promptPassword(final String s)
- {
+ public boolean promptPassword(final String s) {
log.info(s + " - Answer: False");
return false;
}
@Override
- public boolean promptPassphrase(final String s)
- {
+ public boolean promptPassphrase(final String s) {
log.info(s + " - Answer: False");
return false;
}
@Override
- public boolean promptYesNo(final String s)
- {
+ public boolean promptYesNo(final String s) {
log.debug(s + " - Answer: Yes");
// trust
@@ -64,8 +58,7 @@ public class TrustEveryoneUserInfo imple
}
@Override
- public void showMessage(final String s)
- {
+ public void showMessage(final String s) {
log.debug(s);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java Thu Sep 14 19:26:39 2017
@@ -29,22 +29,17 @@ import org.apache.commons.vfs2.provider.
/**
* A file in a Tar file system.
*/
-public class TarFileObject extends AbstractFileObject<TarFileSystem>
-{
+public class TarFileObject extends AbstractFileObject<TarFileSystem> {
/** The TarArchiveEntry */
private TarArchiveEntry entry;
private final HashSet<String> children = new HashSet<>();
private FileType type;
- protected TarFileObject(final AbstractFileName name,
- final TarArchiveEntry entry,
- final TarFileSystem fs,
- final boolean tarExists) throws FileSystemException
- {
+ protected TarFileObject(final AbstractFileName name, final TarArchiveEntry entry, final TarFileSystem fs,
+ final boolean tarExists) throws FileSystemException {
super(name, fs);
setTarEntry(entry);
- if (!tarExists)
- {
+ if (!tarExists) {
type = FileType.IMAGINARY;
}
}
@@ -52,21 +47,16 @@ public class TarFileObject extends Abstr
/**
* Sets the details for this file object.
*
- * Consider this method package private. TODO Might be made package private in the next major version.
+ * Consider this method package private. TODO Might be made package private in the next major version.
*/
- protected void setTarEntry(final TarArchiveEntry entry)
- {
- if (this.entry != null)
- {
+ protected void setTarEntry(final TarArchiveEntry entry) {
+ if (this.entry != null) {
return;
}
- if (entry == null || entry.isDirectory())
- {
+ if (entry == null || entry.isDirectory()) {
type = FileType.FOLDER;
- }
- else
- {
+ } else {
type = FileType.FILE;
}
@@ -75,10 +65,10 @@ public class TarFileObject extends Abstr
/**
* Attaches a child.
+ *
* @param childName Name of child to remember.
*/
- protected void attachChild(final FileName childName)
- {
+ protected void attachChild(final FileName childName) {
children.add(childName.getBaseName());
}
@@ -89,8 +79,7 @@ public class TarFileObject extends Abstr
* @throws FileSystemException if an error occurs.
*/
@Override
- public boolean isWriteable() throws FileSystemException
- {
+ public boolean isWriteable() throws FileSystemException {
return false;
}
@@ -98,8 +87,7 @@ public class TarFileObject extends Abstr
* Returns the file's type.
*/
@Override
- protected FileType doGetType()
- {
+ protected FileType doGetType() {
return type;
}
@@ -107,17 +95,12 @@ public class TarFileObject extends Abstr
* Lists the children of the file.
*/
@Override
- protected String[] doListChildren()
- {
- try
- {
- if (!getType().hasChildren())
- {
+ protected String[] doListChildren() {
+ try {
+ if (!getType().hasChildren()) {
return null;
}
- }
- catch (final FileSystemException e)
- {
+ } catch (final FileSystemException e) {
// should not happen as the type has already been cached.
throw new RuntimeException(e);
}
@@ -126,14 +109,12 @@ public class TarFileObject extends Abstr
}
/**
- * Returns the size of the file content (in bytes). Is only called if
- * {@link #doGetType} returns {@link FileType#FILE}.
+ * Returns the size of the file content (in bytes). Is only called if {@link #doGetType} returns
+ * {@link FileType#FILE}.
*/
@Override
- protected long doGetContentSize()
- {
- if (entry == null)
- {
+ protected long doGetContentSize() {
+ if (entry == null) {
return 0;
}
@@ -144,10 +125,8 @@ public class TarFileObject extends Abstr
* Returns the last modified time of this file.
*/
@Override
- protected long doGetLastModifiedTime() throws Exception
- {
- if (entry == null)
- {
+ protected long doGetLastModifiedTime() throws Exception {
+ if (entry == null) {
return 0;
}
@@ -155,19 +134,16 @@ public class TarFileObject extends Abstr
}
/**
- * Creates an input stream to read the file content from. Is only called
- * if {@link #doGetType} returns {@link FileType#FILE}. The input stream
- * returned by this method is guaranteed to be closed before this
- * method is called again.
+ * Creates an input stream to read the file content from. Is only called if {@link #doGetType} returns
+ * {@link FileType#FILE}. The input stream returned by this method is guaranteed to be closed before this method is
+ * called again.
*/
@Override
- protected InputStream doGetInputStream() throws Exception
- {
+ protected InputStream doGetInputStream() throws Exception {
// VFS-210: zip allows to gather an input stream even from a directory and will
// return -1 on the first read. getType should not be expensive and keeps the tests
// running
- if (!getType().hasContent())
- {
+ if (!getType().hasContent()) {
throw new FileSystemException("vfs.provider/read-not-file.error", getName());
}