Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/WindowsFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -23,33 +23,25 @@ import org.apache.commons.vfs2.FileType; /** * A parser for Windows file names. */ -public class WindowsFileNameParser extends LocalFileNameParser -{ +public class WindowsFileNameParser extends LocalFileNameParser { /** * Pops the root prefix off a URI, which has had the scheme removed. */ @Override - protected String extractRootPrefix(final String uri, - final StringBuilder name) - throws FileSystemException - { + protected String extractRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { return extractWindowsRootPrefix(uri, name); } @Override - protected FileName createFileName(final String scheme, final String rootFile, - final String path, final FileType type) - { + protected FileName createFileName(final String scheme, final String rootFile, final String path, + final FileType type) { return new WindowsFileName(scheme, rootFile, path, type); } /** * Extracts a Windows root prefix from a name. */ - private String extractWindowsRootPrefix(final String uri, - final StringBuilder name) - throws FileSystemException - { + private String extractWindowsRootPrefix(final String uri, final StringBuilder name) throws FileSystemException { // Looking for: // ('/'){0, 3} <letter> ':' '/' // ['/'] '//' <name> '/' <name> ( '/' | <end> ) @@ -57,11 +49,9 @@ public class WindowsFileNameParser exten // Skip over first 4 (unc) leading '/' chars int startPos = 0; final int maxlen = Math.min(4, name.length()); - for (; startPos < maxlen && name.charAt(startPos) == '/'; startPos++) - { + for (; startPos < maxlen && name.charAt(startPos) == '/'; startPos++) { } - if (startPos == maxlen && name.length() > (startPos + 1) && name.charAt(startPos + 1) == '/') - { + if (startPos == maxlen && name.length() > (startPos + 1) && name.charAt(startPos + 1) == '/') { // Too many '/' throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); } @@ -69,14 +59,12 @@ public class WindowsFileNameParser exten // Look for drive name final String driveName = extractDrivePrefix(name); - if (driveName != null) - { + if (driveName != null) { return driveName; } // Look for UNC name - if (startPos < 2) - { + if (startPos < 2) { throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); } @@ -84,29 +72,24 @@ public class WindowsFileNameParser exten } /** - * Extracts a drive prefix from a path. Leading '/' chars have been removed. + * Extracts a drive prefix from a path. Leading '/' chars have been removed. */ - private String extractDrivePrefix(final StringBuilder name) - { + private String extractDrivePrefix(final StringBuilder name) { // Looking for <letter> ':' '/' - if (name.length() < 3) - { + if (name.length() < 3) { // Too short return null; } final char ch = name.charAt(0); - if (ch == '/' || ch == ':') - { + if (ch == '/' || ch == ':') { // Missing drive letter return null; } - if (name.charAt(1) != ':') - { + if (name.charAt(1) != ':') { // Missing ':' return null; } - if (name.charAt(2) != '/') - { + if (name.charAt(2) != '/') { // Missing separator return null; } @@ -118,33 +101,26 @@ public class WindowsFileNameParser exten } /** - * Extracts a UNC name from a path. Leading '/' chars have been removed. + * Extracts a UNC name from a path. Leading '/' chars have been removed. */ - private String extractUNCPrefix(final String uri, - final StringBuilder name) - throws FileSystemException - { + private String extractUNCPrefix(final String uri, final StringBuilder name) throws FileSystemException { // Looking for <name> '/' <name> ( '/' | <end> ) // Look for first separator final int maxpos = name.length(); int pos = 0; - for (; pos < maxpos && name.charAt(pos) != '/'; pos++) - { + for (; pos < maxpos && name.charAt(pos) != '/'; pos++) { } pos++; - if (pos >= maxpos) - { + if (pos >= maxpos) { throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri); } // Now have <name> '/' final int startShareName = pos; - for (; pos < maxpos && name.charAt(pos) != '/'; pos++) - { + for (; pos < maxpos && name.charAt(pos) != '/'; pos++) { } - if (pos == startShareName) - { + if (pos == startShareName) { throw new FileSystemException("vfs.provider.local/missing-share-name.error", uri); }
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java Thu Sep 14 19:26:39 2017 @@ -28,8 +28,7 @@ import org.apache.commons.vfs2.FileType; /** * RAM File Object Data. */ -class RamFileData implements Serializable -{ +class RamFileData implements Serializable { static final byte[] EMPTY = new byte[0]; /** @@ -64,15 +63,14 @@ class RamFileData implements Serializabl /** * Constructor. + * * @param name The file name. */ - public RamFileData(final FileName name) - { + public RamFileData(final FileName name) { super(); this.children = Collections.synchronizedCollection(new ArrayList<RamFileData>()); this.clear(); - if (name == null) - { + if (name == null) { throw new IllegalArgumentException("name can not be null"); } this.name = name; @@ -81,16 +79,14 @@ class RamFileData implements Serializabl /** * @return Returns the buffer. */ - byte[] getContent() - { + byte[] getContent() { return content; } /** * @param content The buffer. */ - void setContent(final byte[] content) - { + void setContent(final byte[] content) { updateLastModified(); this.content = content; } @@ -98,41 +94,34 @@ class RamFileData implements Serializabl /** * @return Returns the lastModified. */ - long getLastModified() - { + long getLastModified() { return lastModified; } /** - * @param lastModified - * The lastModified to set. + * @param lastModified The lastModified to set. */ - void setLastModified(final long lastModified) - { + void setLastModified(final long lastModified) { this.lastModified = lastModified; } /** * @return Returns the type. */ - FileType getType() - { + FileType getType() { return type; } /** - * @param type - * The type to set. + * @param type The type to set. */ - void setType(final FileType type) - { + void setType(final FileType type) { this.type = type; } /** */ - void clear() - { + void clear() { this.content = EMPTY; updateLastModified(); this.type = FileType.IMAGINARY; @@ -140,16 +129,14 @@ class RamFileData implements Serializabl this.name = null; } - void updateLastModified() - { + void updateLastModified() { this.lastModified = System.currentTimeMillis(); } /** * @return Returns the name. */ - FileName getName() - { + FileName getName() { return name; } @@ -159,8 +146,7 @@ class RamFileData implements Serializabl * @see java.lang.Object#toString() */ @Override - public String toString() - { + public String toString() { return this.name.toString(); } @@ -170,21 +156,16 @@ class RamFileData implements Serializabl * @param data The file data. * @throws FileSystemException if an error occurs. */ - void addChild(final RamFileData data) throws FileSystemException - { - if (!this.getType().hasChildren()) - { - throw new FileSystemException( - "A child can only be added in a folder"); + void addChild(final RamFileData data) throws FileSystemException { + if (!this.getType().hasChildren()) { + throw new FileSystemException("A child can only be added in a folder"); } - if (data == null) - { + if (data == null) { throw new FileSystemException("No child can be null"); } - if (this.children.contains(data)) - { + if (this.children.contains(data)) { throw new FileSystemException("Child already exists. " + data); } @@ -198,15 +179,11 @@ class RamFileData implements Serializabl * @param data The file data. * @throws FileSystemException if an error occurs. */ - void removeChild(final RamFileData data) throws FileSystemException - { - if (!this.getType().hasChildren()) - { - throw new FileSystemException( - "A child can only be removed from a folder"); + void removeChild(final RamFileData data) throws FileSystemException { + if (!this.getType().hasChildren()) { + throw new FileSystemException("A child can only be removed from a folder"); } - if (!this.children.contains(data)) - { + if (!this.children.contains(data)) { throw new FileSystemException("Child not found. " + data); } this.children.remove(data); @@ -216,10 +193,8 @@ class RamFileData implements Serializabl /** * @return Returns the children. */ - Collection<RamFileData> getChildren() - { - if (name == null) - { + Collection<RamFileData> getChildren() { + if (name == null) { throw new IllegalStateException("Data is clear"); } return children; @@ -231,14 +206,11 @@ class RamFileData implements Serializabl * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object o) - { - if (this == o) - { + public boolean equals(final Object o) { + if (this == o) { return true; } - if (!(o instanceof RamFileData)) - { + if (!(o instanceof RamFileData)) { return false; } final RamFileData data = (RamFileData) o; @@ -251,21 +223,18 @@ class RamFileData implements Serializabl * @see java.lang.Object#hashCode() */ @Override - public int hashCode() - { + public int hashCode() { return this.getName().hashCode(); } - boolean hasChildren(final RamFileData data) - { + boolean hasChildren(final RamFileData data) { return this.children.contains(data); } /** * @return Returns the size of the buffer */ - int size() - { + int size() { return content.length; } @@ -274,13 +243,11 @@ class RamFileData implements Serializabl * * @param newSize The new buffer size. */ - void resize(final long newSize) - { + void resize(final long newSize) { // A future implementation may allow longs/multiple buffer/and so on - if (newSize > Integer.MAX_VALUE) - { - throw new IllegalArgumentException(String.format("newSize(%d) > Integer.MAX_VALUE(%d)", newSize, - Integer.MAX_VALUE)); + if (newSize > Integer.MAX_VALUE) { + throw new IllegalArgumentException( + String.format("newSize(%d) > Integer.MAX_VALUE(%d)", newSize, Integer.MAX_VALUE)); } final int resize = (int) newSize; final int size = this.size(); Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java Thu Sep 14 19:26:39 2017 @@ -35,27 +35,22 @@ import org.apache.commons.vfs2.util.Rand * A RAM File contains a single RAM FileData instance, it provides methods to access the data by implementing FileObject * interface. */ -public class RamFileObject extends AbstractFileObject<RamFileSystem> -{ +public class RamFileObject extends AbstractFileObject<RamFileSystem> { /** * RAM File Object Data. */ private RamFileData data; /** - * @param name - * The name of the file. - * @param fs - * The FileSystem. + * @param name The name of the file. + * @param fs The FileSystem. */ - protected RamFileObject(final AbstractFileName name, final RamFileSystem fs) - { + protected RamFileObject(final AbstractFileName name, final RamFileSystem fs) { super(name, fs); this.getAbstractFileSystem().attach(this); } - private void save() throws FileSystemException - { + private void save() throws FileSystemException { this.getAbstractFileSystem().save(this); } @@ -65,8 +60,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetType() */ @Override - protected FileType doGetType() throws Exception - { + protected FileType doGetType() throws Exception { return data.getType(); } @@ -76,8 +70,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doListChildren() */ @Override - protected String[] doListChildren() throws Exception - { + protected String[] doListChildren() throws Exception { return this.getAbstractFileSystem().listChildren(this.getName()); } @@ -87,8 +80,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetContentSize() */ @Override - protected long doGetContentSize() throws Exception - { + protected long doGetContentSize() throws Exception { return this.size(); } @@ -98,11 +90,9 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetInputStream() */ @Override - protected InputStream doGetInputStream() throws Exception - { + protected InputStream doGetInputStream() throws Exception { // VFS-210: ram allows to gather an input stream even from a directory. So we need to check the type anyway. - if (!getType().hasContent()) - { + if (!getType().hasContent()) { throw new FileSystemException("vfs.provider/read-not-file.error", getName()); } @@ -115,10 +105,8 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetOutputStream(boolean) */ @Override - protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception - { - if (!bAppend) - { + protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { + if (!bAppend) { this.data.setContent(RamFileData.EMPTY); } return new RamFileOutputStream(this); @@ -130,11 +118,9 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doDelete() */ @Override - protected void doDelete() throws Exception - { + protected void doDelete() throws Exception { - if (this.isContentOpen()) - { + if (this.isContentOpen()) { throw new FileSystemException(this.getName() + " cannot be deleted while the file is openg"); } getAbstractFileSystem().delete(this); @@ -146,8 +132,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetLastModifiedTime() */ @Override - protected long doGetLastModifiedTime() throws Exception - { + protected long doGetLastModifiedTime() throws Exception { return data.getLastModified(); } @@ -158,8 +143,7 @@ public class RamFileObject extends Abstr */ /** @since 2.0 */ @Override - protected boolean doSetLastModifiedTime(final long modtime) throws Exception - { + protected boolean doSetLastModifiedTime(final long modtime) throws Exception { data.setLastModified(modtime); return true; } @@ -170,8 +154,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doCreateFolder() */ @Override - protected void doCreateFolder() throws Exception - { + protected void doCreateFolder() throws Exception { this.injectType(FileType.FOLDER); this.save(); } @@ -182,8 +165,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doRename(org.apache.commons.vfs2.FileObject) */ @Override - protected void doRename(final FileObject newFile) throws Exception - { + protected void doRename(final FileObject newFile) throws Exception { final RamFileObject newRamFileObject = (RamFileObject) FileObjectUtils.getAbstractFileObject(newFile); getAbstractFileSystem().rename(this, newRamFileObject); } @@ -195,8 +177,7 @@ public class RamFileObject extends Abstr * org.apache.commons.vfs2.util.RandomAccessMode) */ @Override - protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception - { + protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception { return new RamFileRandomAccessContent(this, mode); } @@ -206,25 +187,21 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#doAttach() */ @Override - protected void doAttach() throws Exception - { + protected void doAttach() throws Exception { this.getAbstractFileSystem().attach(this); } /** * @return Returns the data. */ - RamFileData getData() - { + RamFileData getData() { return data; } /** - * @param data - * The data to set. + * @param data The data to set. */ - void setData(final RamFileData data) - { + void setData(final RamFileData data) { this.data = data; } @@ -234,8 +211,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#injectType(org.apache.commons.vfs2.FileType) */ @Override - protected void injectType(final FileType fileType) - { + protected void injectType(final FileType fileType) { this.data.setType(fileType); super.injectType(fileType); } @@ -246,8 +222,7 @@ public class RamFileObject extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileObject#endOutput() */ @Override - protected void endOutput() throws Exception - { + protected void endOutput() throws Exception { super.endOutput(); this.save(); } @@ -255,25 +230,20 @@ public class RamFileObject extends Abstr /** * @return Returns the size of the {@link RamFileData}. */ - int size() - { + int size() { return data == null ? 0 : data.size(); } /** * @param newSize - * @throws IOException - * if the new size exceeds the limit + * @throws IOException if the new size exceeds the limit */ - synchronized void resize(final long newSize) throws IOException - { + synchronized void resize(final long newSize) throws IOException { final RamFileSystem afs = getAbstractFileSystem(); final FileSystemOptions afsOptions = afs.getFileSystemOptions(); - if (afsOptions != null) - { + if (afsOptions != null) { final long maxSize = RamFileSystemConfigBuilder.getInstance().getLongMaxSize(afsOptions); - if (afs.size() + newSize - this.size() > maxSize) - { + if (afs.size() + newSize - this.size() > maxSize) { throw new IOException("FileSystem capacity (" + maxSize + ") exceeded."); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileOutputStream.java Thu Sep 14 19:26:39 2017 @@ -24,8 +24,7 @@ import org.apache.commons.vfs2.FileSyste /** * OutputStream to a RamFile. */ -public class RamFileOutputStream extends OutputStream -{ +public class RamFileOutputStream extends OutputStream { /** * File. @@ -45,8 +44,7 @@ public class RamFileOutputStream extends /** * @param file The base file. */ - public RamFileOutputStream(final RamFileObject file) - { + public RamFileOutputStream(final RamFileObject file) { super(); this.file = file; } @@ -57,18 +55,14 @@ public class RamFileOutputStream extends * @see java.io.DataOutput#write(byte[], int, int) */ @Override - public void write(final byte[] b, final int off, final int len) throws IOException - { + public void write(final byte[] b, final int off, final int len) throws IOException { final RamFileData data = this.file.getData(); final int size = data.size(); final int newSize = size + len; // Store the Exception in order to notify the client again on close() - try - { + try { this.file.resize(newSize); - } - catch (final IOException e) - { + } catch (final IOException e) { this.exception = e; throw e; } @@ -81,37 +75,29 @@ public class RamFileOutputStream extends * @see java.io.DataOutput#write(int) */ @Override - public void write(final int b) throws IOException - { + public void write(final int b) throws IOException { buffer1[0] = (byte) b; this.write(buffer1); } @Override - public void flush() throws IOException - { + public void flush() throws IOException { } @Override - public void close() throws IOException - { - if (closed) - { + public void close() throws IOException { + if (closed) { return; } // Notify on close that there was an IOException while writing - if (exception != null) - { + if (exception != null) { throw exception; } - try - { + try { this.closed = true; // Close the this.file.endOutput(); - } - catch (final Exception e) - { + } catch (final Exception e) { throw new FileSystemException(e); } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileProvider.java Thu Sep 14 19:26:39 2017 @@ -30,34 +30,19 @@ import org.apache.commons.vfs2.provider. /** * RAM File Provider. */ -public class RamFileProvider extends AbstractOriginatingFileProvider -{ +public class RamFileProvider extends AbstractOriginatingFileProvider { /** The provider's capabilities. */ - public 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_SET_LENGTH, - Capability.RANDOM_ACCESS_WRITE - })); + public 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_SET_LENGTH, Capability.RANDOM_ACCESS_WRITE })); /** * Constructs a new provider. */ - public RamFileProvider() - { + public RamFileProvider() { super(); } @@ -65,12 +50,11 @@ public class RamFileProvider extends Abs * (non-Javadoc) * * @see org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider#doCreateFileSystem( - * org.apache.commons.vfs2.FileName, org.apache.commons.vfs2.FileSystemOptions) + * org.apache.commons.vfs2.FileName, org.apache.commons.vfs2.FileSystemOptions) */ @Override - protected FileSystem doCreateFileSystem(final FileName name, - final FileSystemOptions fileSystemOptions) throws FileSystemException - { + protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) + throws FileSystemException { return new RamFileSystem(name, fileSystemOptions); } @@ -80,8 +64,7 @@ public class RamFileProvider extends Abs * @see org.apache.commons.vfs2.provider.FileProvider#getCapabilities() */ @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/ram/RamFileRandomAccessContent.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileRandomAccessContent.java Thu Sep 14 19:26:39 2017 @@ -29,8 +29,7 @@ import org.apache.commons.vfs2.util.Rand /** * RAM File Random Access Content. */ -public class RamFileRandomAccessContent implements RandomAccessContent -{ +public class RamFileRandomAccessContent implements RandomAccessContent { /** * File Pointer */ @@ -72,52 +71,41 @@ public class RamFileRandomAccessContent * @param file The file to access. * @param mode The access mode. */ - public RamFileRandomAccessContent(final RamFileObject file, final RandomAccessMode mode) - { + public RamFileRandomAccessContent(final RamFileObject file, final RandomAccessMode mode) { super(); this.buf = file.getData().getContent(); this.file = file; - rafis = new InputStream() - { + rafis = new InputStream() { @Override - public int read() throws IOException - { - try - { + public int read() throws IOException { + try { return readByte(); - } - catch (final EOFException e) - { + } catch (final EOFException e) { return -1; } } @Override - public long skip(final long n) throws IOException - { + public long skip(final long n) throws IOException { seek(getFilePointer() + n); return n; } @Override - public void close() throws IOException - { + public void close() throws IOException { } @Override - public int read(final byte[] b) throws IOException - { + public int read(final byte[] b) throws IOException { return read(b, 0, b.length); } @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 { int retLen = -1; final int left = getLeftBytes(); - if (left > 0) - { + if (left > 0) { retLen = Math.min(len, left); RamFileRandomAccessContent.this.readFully(b, off, retLen); } @@ -125,8 +113,7 @@ public class RamFileRandomAccessContent } @Override - public int available() throws IOException - { + public int available() throws IOException { return getLeftBytes(); } }; @@ -138,8 +125,7 @@ public class RamFileRandomAccessContent * @see org.apache.commons.vfs2.RandomAccessContent#getFilePointer() */ @Override - public long getFilePointer() throws IOException - { + public long getFilePointer() throws IOException { return this.filePointer; } @@ -149,10 +135,8 @@ public class RamFileRandomAccessContent * @see org.apache.commons.vfs2.RandomAccessContent#seek(long) */ @Override - public void seek(final long pos) throws IOException - { - if (pos < 0) - { + public void seek(final long pos) throws IOException { + if (pos < 0) { throw new IOException("Attempt to position before the start of the file"); } this.filePointer = (int) pos; @@ -164,8 +148,7 @@ public class RamFileRandomAccessContent * @see org.apache.commons.vfs2.RandomAccessContent#length() */ @Override - public long length() throws IOException - { + public long length() throws IOException { return buf.length; } @@ -175,8 +158,7 @@ public class RamFileRandomAccessContent * @see org.apache.commons.vfs2.RandomAccessContent#close() */ @Override - public void close() throws IOException - { + public void close() throws IOException { } @@ -186,8 +168,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readByte() */ @Override - public byte readByte() throws IOException - { + public byte readByte() throws IOException { return (byte) this.readUnsignedByte(); } @@ -197,8 +178,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readChar() */ @Override - public char readChar() throws IOException - { + public char readChar() throws IOException { final int ch1 = this.readUnsignedByte(); final int ch2 = this.readUnsignedByte(); return (char) ((ch1 << 8) + (ch2 << 0)); @@ -210,8 +190,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readDouble() */ @Override - public double readDouble() throws IOException - { + public double readDouble() throws IOException { return Double.longBitsToDouble(this.readLong()); } @@ -221,8 +200,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readFloat() */ @Override - public float readFloat() throws IOException - { + public float readFloat() throws IOException { return Float.intBitsToFloat(this.readInt()); } @@ -232,10 +210,8 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readInt() */ @Override - public int readInt() throws IOException - { - return (readUnsignedByte() << 24) | (readUnsignedByte() << 16) - | (readUnsignedByte() << 8) | readUnsignedByte(); + public int readInt() throws IOException { + return (readUnsignedByte() << 24) | (readUnsignedByte() << 16) | (readUnsignedByte() << 8) | readUnsignedByte(); } /* @@ -244,10 +220,8 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readUnsignedByte() */ @Override - public int readUnsignedByte() throws IOException - { - if (filePointer < buf.length) - { + public int readUnsignedByte() throws IOException { + if (filePointer < buf.length) { return buf[filePointer++] & 0xFF; } throw new EOFException(); @@ -259,8 +233,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readUnsignedShort() */ @Override - public int readUnsignedShort() throws IOException - { + public int readUnsignedShort() throws IOException { this.readFully(buffer2); return toUnsignedShort(buffer2); } @@ -271,8 +244,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readLong() */ @Override - public long readLong() throws IOException - { + public long readLong() throws IOException { this.readFully(buffer8); return toLong(buffer8); } @@ -283,8 +255,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readShort() */ @Override - public short readShort() throws IOException - { + public short readShort() throws IOException { this.readFully(buffer2); return toShort(buffer2); } @@ -295,8 +266,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readBoolean() */ @Override - public boolean readBoolean() throws IOException - { + public boolean readBoolean() throws IOException { return this.readUnsignedByte() != 0; } @@ -306,18 +276,14 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#skipBytes(int) */ @Override - public int skipBytes(final int n) throws IOException - { - if (n < 0) - { - throw new IndexOutOfBoundsException( - "The skip number can't be negative"); + public int skipBytes(final int n) throws IOException { + if (n < 0) { + throw new IndexOutOfBoundsException("The skip number can't be negative"); } final long newPos = filePointer + n; - if (newPos > buf.length) - { + if (newPos > buf.length) { throw new IndexOutOfBoundsException("Tyring to skip too much bytes"); } @@ -332,8 +298,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readFully(byte[]) */ @Override - public void readFully(final byte[] b) throws IOException - { + public void readFully(final byte[] b) throws IOException { this.readFully(b, 0, b.length); } @@ -343,18 +308,14 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readFully(byte[], int, int) */ @Override - public void readFully(final byte[] b, final int off, final int len) throws IOException - { - if (len < 0) - { + public void readFully(final byte[] b, final int off, final int len) throws IOException { + if (len < 0) { throw new IndexOutOfBoundsException("Length is lower than 0"); } - if (len > this.getLeftBytes()) - { - throw new IndexOutOfBoundsException("Read length (" + len - + ") is higher than buffer left bytes (" - + this.getLeftBytes() + ") "); + if (len > this.getLeftBytes()) { + throw new IndexOutOfBoundsException( + "Read length (" + len + ") is higher than buffer left bytes (" + this.getLeftBytes() + ") "); } System.arraycopy(buf, filePointer, b, off, len); @@ -362,8 +323,7 @@ public class RamFileRandomAccessContent filePointer += len; } - private int getLeftBytes() - { + private int getLeftBytes() { return buf.length - filePointer; } @@ -373,8 +333,7 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readUTF() */ @Override - public String readUTF() throws IOException - { + public String readUTF() throws IOException { return DataInputStream.readUTF(this); } @@ -384,10 +343,8 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#write(byte[], int, int) */ @Override - public void write(final byte[] b, final int off, final int len) throws IOException - { - if (this.getLeftBytes() < len) - { + public void write(final byte[] b, final int off, final int len) throws IOException { + if (this.getLeftBytes() < len) { final int newSize = this.buf.length + len - this.getLeftBytes(); this.file.resize(newSize); this.buf = this.file.getData().getContent(); @@ -402,8 +359,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#write(byte[]) */ @Override - public void write(final byte[] b) throws IOException - { + public void write(final byte[] b) throws IOException { this.write(b, 0, b.length); } @@ -413,8 +369,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeByte(int) */ @Override - public void writeByte(final int i) throws IOException - { + public void writeByte(final int i) throws IOException { this.write(i); } @@ -424,26 +379,20 @@ public class RamFileRandomAccessContent * @param b The byte[] to convert. * @return A long. */ - public static long toLong(final byte[] b) - { - return ((((long) b[7]) & 0xFF) + ((((long) b[6]) & 0xFF) << 8) - + ((((long) b[5]) & 0xFF) << 16) - + ((((long) b[4]) & 0xFF) << 24) - + ((((long) b[3]) & 0xFF) << 32) - + ((((long) b[2]) & 0xFF) << 40) + public static long toLong(final byte[] b) { + return ((((long) b[7]) & 0xFF) + ((((long) b[6]) & 0xFF) << 8) + ((((long) b[5]) & 0xFF) << 16) + + ((((long) b[4]) & 0xFF) << 24) + ((((long) b[3]) & 0xFF) << 32) + ((((long) b[2]) & 0xFF) << 40) + ((((long) b[1]) & 0xFF) << 48) + ((((long) b[0]) & 0xFF) << 56)); } /** - * Build a 8-byte array from a long. No check is performed on the array - * length. + * Build a 8-byte array from a long. No check is performed on the array length. * * @param n The number to convert. * @param b The array to fill. * @return A byte[]. */ - public static byte[] toBytes(long n, final byte[] b) - { + public static byte[] toBytes(long n, final byte[] b) { b[7] = (byte) (n); n >>>= 8; b[6] = (byte) (n); @@ -464,11 +413,11 @@ public class RamFileRandomAccessContent /** * Build a short from first 2 bytes of the array. + * * @param b The byte[] to convert. * @return A short. */ - public static short toShort(final byte[] b) - { + public static short toShort(final byte[] b) { return (short) toUnsignedShort(b); } @@ -478,8 +427,7 @@ public class RamFileRandomAccessContent * @param b The byte[] to convert. * @return A short. */ - public static int toUnsignedShort(final byte[] b) - { + public static int toUnsignedShort(final byte[] b) { return ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8)); } @@ -489,8 +437,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#write(int) */ @Override - public void write(final int b) throws IOException - { + public void write(final int b) throws IOException { buffer1[0] = (byte) b; this.write(buffer1); } @@ -501,8 +448,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeBoolean(boolean) */ @Override - public void writeBoolean(final boolean v) throws IOException - { + public void writeBoolean(final boolean v) throws IOException { this.write(v ? 1 : 0); } @@ -512,8 +458,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeBytes(java.lang.String) */ @Override - public void writeBytes(final String s) throws IOException - { + public void writeBytes(final String s) throws IOException { write(s.getBytes()); } @@ -523,8 +468,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeChar(int) */ @Override - public void writeChar(final int v) throws IOException - { + public void writeChar(final int v) throws IOException { buffer2[0] = (byte) ((v >>> 8) & 0xFF); buffer2[1] = (byte) ((v >>> 0) & 0xFF); write(buffer2); @@ -536,11 +480,9 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeChars(java.lang.String) */ @Override - public void writeChars(final String s) throws IOException - { + public void writeChars(final String s) throws IOException { final int len = s.length(); - for (int i = 0; i < len; i++) - { + for (int i = 0; i < len; i++) { writeChar(s.charAt(i)); } } @@ -551,8 +493,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeDouble(double) */ @Override - public void writeDouble(final double v) throws IOException - { + public void writeDouble(final double v) throws IOException { writeLong(Double.doubleToLongBits(v)); } @@ -562,8 +503,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeFloat(float) */ @Override - public void writeFloat(final float v) throws IOException - { + public void writeFloat(final float v) throws IOException { writeInt(Float.floatToIntBits(v)); } @@ -573,8 +513,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeInt(int) */ @Override - public void writeInt(final int v) throws IOException - { + public void writeInt(final int v) throws IOException { buffer4[0] = (byte) ((v >>> 24) & 0xFF); buffer4[1] = (byte) ((v >>> 16) & 0xFF); buffer4[2] = (byte) ((v >>> 8) & 0xFF); @@ -588,8 +527,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeLong(long) */ @Override - public void writeLong(final long v) throws IOException - { + public void writeLong(final long v) throws IOException { write(toBytes(v, buffer8)); } @@ -599,8 +537,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeShort(int) */ @Override - public void writeShort(final int v) throws IOException - { + public void writeShort(final int v) throws IOException { buffer2[0] = (byte) ((v >>> 8) & 0xFF); buffer2[1] = (byte) (v & 0xFF); write(buffer2); @@ -612,8 +549,7 @@ public class RamFileRandomAccessContent * @see java.io.DataOutput#writeUTF(java.lang.String) */ @Override - public void writeUTF(final String str) throws IOException - { + public void writeUTF(final String str) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(str.length()); final DataOutputStream dataOut = new DataOutputStream(out); dataOut.writeUTF(str); @@ -629,20 +565,17 @@ public class RamFileRandomAccessContent * @see java.io.DataInput#readLine() */ @Override - public String readLine() throws IOException - { + public String readLine() throws IOException { throw new UnsupportedOperationException("deprecated"); } @Override - public InputStream getInputStream() throws IOException - { + public InputStream getInputStream() throws IOException { return rafis; } @Override - public void setLength(final long newLength) throws IOException - { + public void setLength(final long newLength) throws IOException { this.file.resize(newLength); this.buf = this.file.getData().getContent(); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java Thu Sep 14 19:26:39 2017 @@ -40,8 +40,7 @@ import org.apache.commons.vfs2.provider. /** * A RAM File System. */ -public class RamFileSystem extends AbstractFileSystem implements Serializable -{ +public class RamFileSystem extends AbstractFileSystem implements Serializable { private static final int BUFFER_SIZE = 512; /** @@ -58,8 +57,7 @@ public class RamFileSystem extends Abstr * @param rootName The root file name. * @param fileSystemOptions The FileSystem options. */ - protected RamFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) - { + protected RamFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) { super(rootName, null, fileSystemOptions); this.cache = Collections.synchronizedMap(new HashMap<FileName, RamFileData>()); // create root @@ -75,8 +73,7 @@ public class RamFileSystem extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileSystem#createFile(org.apache.commons.vfs2.FileName) */ @Override - protected FileObject createFile(final AbstractFileName name) throws Exception - { + protected FileObject createFile(final AbstractFileName name) throws Exception { return new RamFileObject(name, this); } @@ -86,8 +83,7 @@ public class RamFileSystem extends Abstr * @see org.apache.commons.vfs2.provider.AbstractFileSystem#addCapabilities(java.util.Collection) */ @Override - protected void addCapabilities(final Collection<Capability> caps) - { + protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(RamFileProvider.capabilities); } @@ -95,24 +91,20 @@ public class RamFileSystem extends Abstr * @param name The name of the file. * @return children The names of the children. */ - String[] listChildren(final FileName name) - { + String[] listChildren(final FileName name) { final RamFileData data = this.cache.get(name); - if (data == null || !data.getType().hasChildren()) - { + if (data == null || !data.getType().hasChildren()) { return null; } final Collection<RamFileData> children = data.getChildren(); String[] names; - synchronized (children) - { + synchronized (children) { names = new String[children.size()]; int pos = 0; final Iterator<RamFileData> iter = children.iterator(); - while (iter.hasNext()) - { + while (iter.hasNext()) { final RamFileData childData = iter.next(); names[pos] = childData.getName().getBaseName(); pos++; @@ -128,19 +120,16 @@ public class RamFileSystem extends Abstr * @param file * @throws FileSystemException */ - void delete(final RamFileObject file) throws FileSystemException - { + void delete(final RamFileObject file) throws FileSystemException { // root is read only check - if (file.getParent() == null) - { + if (file.getParent() == null) { throw new FileSystemException("unable to delete root"); } // Remove reference from cache this.cache.remove(file.getName()); // Notify the parent - final RamFileObject parent = (RamFileObject) this.resolveFile(file - .getParent().getName()); + final RamFileObject parent = (RamFileObject) this.resolveFile(file.getParent().getName()); parent.getData().removeChild(file.getData()); parent.close(); // Close the file @@ -154,23 +143,18 @@ public class RamFileSystem extends Abstr * @param file * @throws FileSystemException */ - void save(final RamFileObject file) throws FileSystemException - { + void save(final RamFileObject file) throws FileSystemException { // Validate name - if (file.getData().getName() == null) - { - throw new FileSystemException(new IllegalStateException( - "The data has no name. " + file)); + if (file.getData().getName() == null) { + throw new FileSystemException(new IllegalStateException("The data has no name. " + file)); } // Add to the parent - if (file.getName().getDepth() > 0) - { + if (file.getName().getDepth() > 0) { final RamFileData parentData = this.cache.get(file.getParent().getName()); // Only if not already added - if (!parentData.hasChildren(file.getData())) - { + if (!parentData.hasChildren(file.getData())) { final RamFileObject parent = (RamFileObject) file.getParent(); parent.getData().addChild(file.getData()); parent.close(); @@ -187,13 +171,9 @@ public class RamFileSystem extends Abstr * @param to The new file. * @throws FileSystemException if an error occurs. */ - void rename(final RamFileObject from, final RamFileObject to) - throws FileSystemException - { - if (!this.cache.containsKey(from.getName())) - { - throw new FileSystemException("File does not exist: " - + from.getName()); + void rename(final RamFileObject from, final RamFileObject to) throws FileSystemException { + if (!this.cache.containsKey(from.getName())) { + throw new FileSystemException("File does not exist: " + from.getName()); } // Copy data @@ -205,15 +185,12 @@ public class RamFileSystem extends Abstr this.delete(from); } - public void attach(final RamFileObject fo) - { - if (fo.getName() == null) - { + public void attach(final RamFileObject fo) { + if (fo.getName() == null) { throw new IllegalArgumentException("Null argument"); } RamFileData data = this.cache.get(fo.getName()); - if (data == null) - { + if (data == null) { data = new RamFileData(fo.getName()); } fo.setData(data); @@ -225,8 +202,7 @@ public class RamFileSystem extends Abstr * @param file The File * @throws FileSystemException if an error occurs. */ - public void importTree(final File file) throws FileSystemException - { + public void importTree(final File file) throws FileSystemException { final FileObject fileFo = getFileSystemManager().toFileObject(file); this.toRamFileObject(fileFo, fileFo); } @@ -238,76 +214,52 @@ public class RamFileSystem extends Abstr * @param root * @throws FileSystemException */ - void toRamFileObject(final FileObject fo, final FileObject root) - throws FileSystemException - { - final RamFileObject memFo = (RamFileObject) this.resolveFile(fo.getName() - .getPath().substring(root.getName().getPath().length())); - if (fo.getType().hasChildren()) - { + void toRamFileObject(final FileObject fo, final FileObject root) throws FileSystemException { + final RamFileObject memFo = (RamFileObject) this + .resolveFile(fo.getName().getPath().substring(root.getName().getPath().length())); + if (fo.getType().hasChildren()) { // Create Folder memFo.createFolder(); // Import recursively final FileObject[] fos = fo.getChildren(); - for (final FileObject child : fos) - { + for (final FileObject child : fos) { this.toRamFileObject(child, root); } - } - else if (fo.isFile()) - { + } else if (fo.isFile()) { // Read bytes - try - { + try { final InputStream is = fo.getContent().getInputStream(); - try - { - final OutputStream os = new BufferedOutputStream(memFo - .getOutputStream(), BUFFER_SIZE); + try { + final OutputStream os = new BufferedOutputStream(memFo.getOutputStream(), BUFFER_SIZE); int i; - while ((i = is.read()) != -1) - { + while ((i = is.read()) != -1) { os.write(i); } os.close(); - } - finally - { - try - { + } finally { + try { is.close(); - } - catch (final IOException ignored) - { + } catch (final IOException ignored) { /* ignore on close exception. */ } // TODO: close os } + } catch (final IOException e) { + throw new FileSystemException(e.getClass().getName() + " " + e.getMessage()); } - catch (final IOException e) - { - throw new FileSystemException(e.getClass().getName() + " " - + e.getMessage()); - } - } - else - { - throw new FileSystemException("File is not a folder nor a file " - + memFo); + } else { + throw new FileSystemException("File is not a folder nor a file " + memFo); } } /** * @return Returns the size of the FileSystem */ - long size() - { + long size() { long size = 0; - synchronized (cache) - { + synchronized (cache) { final Iterator<RamFileData> iter = cache.values().iterator(); - while (iter.hasNext()) - { + while (iter.hasNext()) { final RamFileData data = iter.next(); size += data.size(); } @@ -319,8 +271,7 @@ public class RamFileSystem extends Abstr * Close the RAMFileSystem. */ @Override - public void close() - { + public void close() { this.cache.clear(); super.close(); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystemConfigBuilder.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystemConfigBuilder.java Thu Sep 14 19:26:39 2017 @@ -23,8 +23,7 @@ import org.apache.commons.vfs2.FileSyste /** * Config Builder for the RAM filesystem. */ -public final class RamFileSystemConfigBuilder extends FileSystemConfigBuilder -{ +public final class RamFileSystemConfigBuilder extends FileSystemConfigBuilder { /** max size key. */ private static final String MAX_SIZE_KEY = "maxsize"; @@ -35,8 +34,7 @@ public final class RamFileSystemConfigBu /** * Constructor */ - private RamFileSystemConfigBuilder() - { + private RamFileSystemConfigBuilder() { super("ram."); } @@ -45,8 +43,7 @@ public final class RamFileSystemConfigBu * * @return the singleton builder. */ - public static RamFileSystemConfigBuilder getInstance() - { + public static RamFileSystemConfigBuilder getInstance() { return SINGLETON; } @@ -54,8 +51,7 @@ public final class RamFileSystemConfigBu * {@inheritDoc} */ @Override - protected Class<? extends FileSystem> getConfigClass() - { + protected Class<? extends FileSystem> getConfigClass() { return RamFileSystem.class; } @@ -67,8 +63,7 @@ public final class RamFileSystemConfigBu * @see #setMaxSize(FileSystemOptions, long) * @since 2.1 */ - public long getLongMaxSize(final FileSystemOptions opts) - { + public long getLongMaxSize(final FileSystemOptions opts) { return getLong(opts, MAX_SIZE_KEY, Long.MAX_VALUE); } @@ -79,8 +74,7 @@ public final class RamFileSystemConfigBu * @return The maximum size of the file. The next major version will change the return type to a long. * @see #setMaxSize(FileSystemOptions, int) */ - public int getMaxSize(final FileSystemOptions opts) - { + public int getMaxSize(final FileSystemOptions opts) { return getLong(opts, MAX_SIZE_KEY, Long.valueOf(Integer.MAX_VALUE)).intValue(); } @@ -92,8 +86,7 @@ public final class RamFileSystemConfigBu * @deprecated Use {@link #setMaxSize(FileSystemOptions, long)} */ @Deprecated - public void setMaxSize(final FileSystemOptions opts, final int sizeInBytes) - { + public void setMaxSize(final FileSystemOptions opts, final int sizeInBytes) { setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes)); } @@ -103,8 +96,7 @@ public final class RamFileSystemConfigBu * @param opts The FileSystem options. * @param sizeInBytes The maximum file size. */ - public void setMaxSize(final FileSystemOptions opts, final long sizeInBytes) - { + public void setMaxSize(final FileSystemOptions opts, final long sizeInBytes) { setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes)); } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileProvider.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileProvider.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileProvider.java Thu Sep 14 19:26:39 2017 @@ -33,24 +33,20 @@ import org.apache.commons.vfs2.provider. /** * The Resource provider. */ -public class ResourceFileProvider extends AbstractFileProvider -{ +public class ResourceFileProvider extends AbstractFileProvider { /** The provider's capabilities */ - protected static final Collection<Capability> capabilities = - Collections.unmodifiableCollection(Arrays.asList(new Capability[] - { - Capability.DISPATCHER - })); + protected static final Collection<Capability> capabilities = Collections + .unmodifiableCollection(Arrays.asList(new Capability[] { Capability.DISPATCHER })); private static final int BUFFER_SIZE = 80; - public ResourceFileProvider() - { + public ResourceFileProvider() { super(); } /** * Locates a file object, by absolute URI. + * * @param baseFile The base file. * @param uri The URI of the file to locate. * @param fileSystemOptions The FileSystem options. @@ -58,24 +54,19 @@ public class ResourceFileProvider extend * @throws FileSystemException if an error occurs. */ @Override - public FileObject findFile(final FileObject baseFile, - final String uri, - final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + public FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) + throws FileSystemException { final StringBuilder buf = new StringBuilder(BUFFER_SIZE); UriParser.extractScheme(uri, buf); final String resourceName = buf.toString(); ClassLoader cl = ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions); - if (cl == null) - { + if (cl == null) { cl = getClass().getClassLoader(); } final URL url = cl.getResource(resourceName); - if (url == null) - { + if (url == null) { throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri); } @@ -83,20 +74,17 @@ public class ResourceFileProvider extend } @Override - public FileSystemConfigBuilder getConfigBuilder() - { + public FileSystemConfigBuilder getConfigBuilder() { return org.apache.commons.vfs2.provider.res.ResourceFileSystemConfigBuilder.getInstance(); } @Override - public void closeFileSystem(final FileSystem filesystem) - { + public void closeFileSystem(final FileSystem filesystem) { // no filesystem created here - so nothing to do } @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/res/ResourceFileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java Thu Sep 14 19:26:39 2017 @@ -24,12 +24,10 @@ import org.apache.commons.vfs2.provider. /** * The config BUILDER for various ftp configuration options. */ -public final class ResourceFileSystemConfigBuilder extends FileSystemConfigBuilder -{ +public final class ResourceFileSystemConfigBuilder extends FileSystemConfigBuilder { private static final ResourceFileSystemConfigBuilder BUILDER = new ResourceFileSystemConfigBuilder(); - private ResourceFileSystemConfigBuilder() - { + private ResourceFileSystemConfigBuilder() { super("resource."); } @@ -38,25 +36,20 @@ public final class ResourceFileSystemCon * * @return the singleton builder. */ - public static ResourceFileSystemConfigBuilder getInstance() - { + public static ResourceFileSystemConfigBuilder getInstance() { return BUILDER; } - - public void setClassLoader(final FileSystemOptions opts, final ClassLoader classLoader) - { + public void setClassLoader(final FileSystemOptions opts, final ClassLoader classLoader) { setParam(opts, ClassLoader.class.getName(), classLoader); } - public ClassLoader getClassLoader(final FileSystemOptions opts) - { + public ClassLoader getClassLoader(final FileSystemOptions opts) { return (ClassLoader) getParam(opts, ClassLoader.class.getName()); } @Override - protected Class<? extends FileSystem> getConfigClass() - { + protected Class<? extends FileSystem> getConfigClass() { return UrlFileSystem.class; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityInfo.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityInfo.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityInfo.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityInfo.java Thu Sep 14 19:26:39 2017 @@ -18,14 +18,12 @@ package org.apache.commons.vfs2.provider import java.io.File; - /** * Structure for an identity. * * @since 2.1 */ -public class IdentityInfo -{ +public class IdentityInfo { private final File privateKey; private final File publicKey; private final byte[] passPhrase; @@ -40,8 +38,7 @@ public class IdentityInfo * @param privateKey The file with the private key * @since 2.1 */ - public IdentityInfo(final File privateKey) - { + public IdentityInfo(final File privateKey) { this(privateKey, null, null); } @@ -54,8 +51,7 @@ public class IdentityInfo * @param passPhrase The passphrase to decrypt the private key (can be {@code null} if no passphrase is used) * @since 2.1 */ - public IdentityInfo(final File privateKey, final byte[] passPhrase) - { + public IdentityInfo(final File privateKey, final byte[] passPhrase) { this(privateKey, null, passPhrase); } @@ -69,8 +65,7 @@ public class IdentityInfo * @param passPhrase The passphrase to decrypt the private key (can be {@code null} if no passphrase is used) * @since 2.1 */ - public IdentityInfo(final File privateKey, final File publicKey, final byte[] passPhrase) - { + public IdentityInfo(final File privateKey, final File publicKey, final byte[] passPhrase) { this.privateKey = privateKey; this.publicKey = publicKey; this.passPhrase = passPhrase; @@ -82,8 +77,7 @@ public class IdentityInfo * @return the file * @since 2.1 */ - public File getPrivateKey() - { + public File getPrivateKey() { return privateKey; } @@ -93,8 +87,7 @@ public class IdentityInfo * @return the file * @since 2.1 */ - public File getPublicKey() - { + public File getPublicKey() { return publicKey; } @@ -104,8 +97,7 @@ public class IdentityInfo * @return the passphrase * @since 2.1 */ - public byte[] getPassPhrase() - { + public byte[] getPassPhrase() { return passPhrase; } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityRepositoryFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityRepositoryFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityRepositoryFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/IdentityRepositoryFactory.java Thu Sep 14 19:26:39 2017 @@ -24,13 +24,11 @@ import com.jcraft.jsch.JSch; * * @version $Id$ */ -public interface IdentityRepositoryFactory -{ +public interface IdentityRepositoryFactory { /** * Creates an Identity repository for a given JSch instance. * - * @param jsch - * JSch context + * @param jsch JSch context * @return a new IdentityRepository */ IdentityRepository create(JSch jsch); Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java Thu Sep 14 19:26:39 2017 @@ -37,19 +37,16 @@ import com.jcraft.jsch.UserInfo; /** * Create a JSch Session instance. */ -public final class SftpClientFactory -{ +public final class SftpClientFactory { private static final String SSH_DIR_NAME = ".ssh"; private static final Log LOG = LogFactory.getLog(SftpClientFactory.class); - static - { + static { JSch.setLogger(new JSchLogger()); } - private SftpClientFactory() - { + private SftpClientFactory() { } /** @@ -64,9 +61,7 @@ public final class SftpClientFactory * @throws FileSystemException if an error occurs. */ public static Session createConnection(final String hostname, final int port, final char[] username, - final char[] password, final FileSystemOptions fileSystemOptions) - throws FileSystemException - { + final char[] password, final FileSystemOptions fileSystemOptions) throws FileSystemException { final JSch jsch = new JSch(); File sshDir = null; @@ -81,31 +76,26 @@ public final class SftpClientFactory setKnownHosts(jsch, sshDir, knownHostsFile); - if (repositoryFactory != null) - { + if (repositoryFactory != null) { jsch.setIdentityRepository(repositoryFactory.create(jsch)); } addIdentities(jsch, sshDir, identities); Session session; - try - { + try { session = jsch.getSession(new String(username), hostname, port); - if (password != null) - { + if (password != null) { session.setPassword(new String(password)); } final Integer timeout = builder.getTimeout(fileSystemOptions); - if (timeout != null) - { + if (timeout != null) { session.setTimeout(timeout.intValue()); } final UserInfo userInfo = builder.getUserInfo(fileSystemOptions); - if (userInfo != null) - { + if (userInfo != null) { session.setUserInfo(userInfo); } @@ -113,60 +103,47 @@ public final class SftpClientFactory // set StrictHostKeyChecking property final String strictHostKeyChecking = builder.getStrictHostKeyChecking(fileSystemOptions); - if (strictHostKeyChecking != null) - { + if (strictHostKeyChecking != null) { config.setProperty("StrictHostKeyChecking", strictHostKeyChecking); } // set PreferredAuthentications property final String preferredAuthentications = builder.getPreferredAuthentications(fileSystemOptions); - if (preferredAuthentications != null) - { + if (preferredAuthentications != null) { config.setProperty("PreferredAuthentications", preferredAuthentications); } // set compression property final String compression = builder.getCompression(fileSystemOptions); - if (compression != null) - { + if (compression != null) { config.setProperty("compression.s2c", compression); config.setProperty("compression.c2s", compression); } final String proxyHost = builder.getProxyHost(fileSystemOptions); - if (proxyHost != null) - { + if (proxyHost != null) { final int proxyPort = builder.getProxyPort(fileSystemOptions); final SftpFileSystemConfigBuilder.ProxyType proxyType = builder.getProxyType(fileSystemOptions); Proxy proxy = null; - if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) - { + if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { proxy = createProxyHTTP(proxyHost, proxyPort); - } - else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) - { + } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { proxy = createProxySOCKS5(proxyHost, proxyPort); - } - else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) - { + } else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) { proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder); } - if (proxy != null) - { + if (proxy != null) { session.setProxy(proxy); } } // set properties for the session - if (config.size() > 0) - { + if (config.size() > 0) { session.setConfig(config); } session.setDaemonThread(true); session.connect(); - } - catch (final Exception exc) - { + } catch (final Exception exc) { throw new FileSystemException("vfs.provider.sftp/connect.error", exc, hostname); } @@ -174,71 +151,50 @@ public final class SftpClientFactory } private static void addIdentities(final JSch jsch, final File sshDir, final IdentityInfo[] identities) - throws FileSystemException - { - if (identities != null) - { - for (final IdentityInfo info : identities) - { + throws FileSystemException { + if (identities != null) { + for (final IdentityInfo info : identities) { addIndentity(jsch, info); } - } - else - { + } else { // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); - if (privateKeyFile.isFile() && privateKeyFile.canRead()) - { + if (privateKeyFile.isFile() && privateKeyFile.canRead()) { addIndentity(jsch, new IdentityInfo(privateKeyFile)); } } } - private static void addIndentity(final JSch jsch, final IdentityInfo info) - throws FileSystemException - { - try - { + private static void addIndentity(final JSch jsch, final IdentityInfo info) throws FileSystemException { + try { final String privateKeyFile = info.getPrivateKey() != null ? info.getPrivateKey().getAbsolutePath() : null; final String publicKeyFile = info.getPublicKey() != null ? info.getPublicKey().getAbsolutePath() : null; jsch.addIdentity(privateKeyFile, publicKeyFile, info.getPassPhrase()); - } - catch (final JSchException e) - { + } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/load-private-key.error", info, e); } } private static void setKnownHosts(final JSch jsch, final File sshDir, File knownHostsFile) - throws FileSystemException - { - try - { - if (knownHostsFile != null) - { + throws FileSystemException { + try { + if (knownHostsFile != null) { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); - } - else - { + } else { // Load the known hosts file knownHostsFile = new File(sshDir, "known_hosts"); - if (knownHostsFile.isFile() && knownHostsFile.canRead()) - { + if (knownHostsFile.isFile() && knownHostsFile.canRead()) { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); } } - } - catch (final JSchException e) - { + } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e); } } private static Proxy createStreamProxy(final String proxyHost, final int proxyPort, - final FileSystemOptions fileSystemOptions, - final SftpFileSystemConfigBuilder builder) - { + final FileSystemOptions fileSystemOptions, final SftpFileSystemConfigBuilder builder) { Proxy proxy; // Use a stream proxy, i.e. it will use a remote host as a proxy // and run a command (e.g. netcat) that forwards input/output @@ -257,13 +213,11 @@ public final class SftpClientFactory return proxy; } - private static ProxySOCKS5 createProxySOCKS5(final String proxyHost, final int proxyPort) - { + private static ProxySOCKS5 createProxySOCKS5(final String proxyHost, final int proxyPort) { return proxyPort == 0 ? new ProxySOCKS5(proxyHost) : new ProxySOCKS5(proxyHost, proxyPort); } - private static ProxyHTTP createProxyHTTP(final String proxyHost, final int proxyPort) - { + private static ProxyHTTP createProxyHTTP(final String proxyHost, final int proxyPort) { return proxyPort == 0 ? new ProxyHTTP(proxyHost) : new ProxyHTTP(proxyHost, proxyPort); } @@ -272,45 +226,37 @@ public final class SftpClientFactory * <p> * The lookup order is: * <ol> - * <li>The system property {@code vfs.sftp.sshdir} (the override - * mechanism)</li> + * <li>The system property {@code vfs.sftp.sshdir} (the override mechanism)</li> * <li>{user.home}/.ssh</li> * <li>On Windows only: C:\cygwin\home\{user.name}\.ssh</li> * <li>The current directory, as a last resort.</li> * <ol> * Windows Notes:<br> - * The default installation directory for Cygwin is {@code C:\cygwin}. - * On my set up (Gary here), I have Cygwin in C:\bin\cygwin, not the default. - * Also, my .ssh directory was created in the {user.home} directory. + * The default installation directory for Cygwin is {@code C:\cygwin}. On my set up (Gary here), I have Cygwin in + * C:\bin\cygwin, not the default. Also, my .ssh directory was created in the {user.home} directory. * * @return The .ssh directory */ - private static File findSshDir() - { + private static File findSshDir() { String sshDirPath; sshDirPath = System.getProperty("vfs.sftp.sshdir"); - if (sshDirPath != null) - { + if (sshDirPath != null) { final File sshDir = new File(sshDirPath); - if (sshDir.exists()) - { + if (sshDir.exists()) { return sshDir; } } File sshDir = new File(System.getProperty("user.home"), SSH_DIR_NAME); - if (sshDir.exists()) - { + if (sshDir.exists()) { return sshDir; } - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) - { + if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { // TODO - this may not be true final String userName = System.getProperty("user.name"); sshDir = new File("C:\\cygwin\\home\\" + userName + "\\" + SSH_DIR_NAME); - if (sshDir.exists()) - { + if (sshDir.exists()) { return sshDir; } } @@ -318,51 +264,46 @@ public final class SftpClientFactory } /** Interface JSchLogger with JCL. */ - private static class JSchLogger implements Logger - { + private static class JSchLogger implements Logger { @Override - public boolean isEnabled(final int level) - { - switch (level) - { - case FATAL: - return LOG.isFatalEnabled(); - case ERROR: - return LOG.isErrorEnabled(); - case WARN: - return LOG.isDebugEnabled(); - case DEBUG: - return LOG.isDebugEnabled(); - case INFO: - return LOG.isInfoEnabled(); - default: - return LOG.isDebugEnabled(); + public boolean isEnabled(final int level) { + switch (level) { + case FATAL: + return LOG.isFatalEnabled(); + case ERROR: + return LOG.isErrorEnabled(); + case WARN: + return LOG.isDebugEnabled(); + case DEBUG: + return LOG.isDebugEnabled(); + case INFO: + return LOG.isInfoEnabled(); + default: + return LOG.isDebugEnabled(); } } @Override - public void log(final int level, final String msg) - { - switch (level) - { - case FATAL: - LOG.fatal(msg); - break; - case ERROR: - LOG.error(msg); - break; - case WARN: - LOG.warn(msg); - break; - case DEBUG: - LOG.debug(msg); - break; - case INFO: - LOG.info(msg); - break; - default: - LOG.debug(msg); + public void log(final int level, final String msg) { + switch (level) { + case FATAL: + LOG.fatal(msg); + break; + case ERROR: + LOG.error(msg); + break; + case WARN: + LOG.warn(msg); + break; + case DEBUG: + LOG.debug(msg); + break; + case INFO: + LOG.info(msg); + break; + default: + LOG.debug(msg); } } } Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileNameParser.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileNameParser.java?rev=1808381&r1=1808380&r2=1808381&view=diff ============================================================================== --- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileNameParser.java (original) +++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileNameParser.java Thu Sep 14 19:26:39 2017 @@ -22,8 +22,7 @@ import org.apache.commons.vfs2.provider. /** * Implementation for SFTP. Sets the default port to 22. */ -public class SftpFileNameParser extends URLFileNameParser -{ +public class SftpFileNameParser extends URLFileNameParser { private static final int DEFAULT_PORT = 22; private static final SftpFileNameParser INSTANCE = new SftpFileNameParser(); @@ -31,8 +30,7 @@ public class SftpFileNameParser extends /** * Creates a new instance with a the default port 22. */ - public SftpFileNameParser() - { + public SftpFileNameParser() { super(DEFAULT_PORT); } @@ -41,8 +39,7 @@ public class SftpFileNameParser extends * * @return the singleton instance. */ - public static FileNameParser getInstance() - { + public static FileNameParser getInstance() { return INSTANCE; } }
