diff src/ch/ethz/ssh2/SFTPv3Client.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents d2b303406d63
children
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/SFTPv3Client.java	Wed Jul 30 12:09:51 2014 -0700
+++ b/src/ch/ethz/ssh2/SFTPv3Client.java	Wed Jul 30 14:16:58 2014 -0700
@@ -101,7 +101,6 @@
             public void read(String packet) {
                 log.debug("Read packet " + packet);
             }
-
             public void write(String packet) {
                 log.debug("Write packet " + packet);
             }
@@ -121,29 +120,24 @@
 
     public SFTPv3FileAttributes fstat(SFTPFileHandle handle) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(handle.getHandle(), 0, handle.getHandle().length);
-
         sendMessage(Packet.SSH_FXP_FSTAT, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_ATTRS) {
+        if (t == Packet.SSH_FXP_ATTRS) {
             return new SFTPv3FileAttributes(tr);
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -155,29 +149,24 @@
 
     private SFTPv3FileAttributes statBoth(String path, int statMethod) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(path, this.getCharset());
-
         sendMessage(statMethod, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_ATTRS) {
+        if (t == Packet.SSH_FXP_ATTRS) {
             return new SFTPv3FileAttributes(tr);
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -199,55 +188,56 @@
     private List<SFTPv3DirectoryEntry> scanDirectory(byte[] handle) throws IOException {
         List<SFTPv3DirectoryEntry> files = new ArrayList<SFTPv3DirectoryEntry>();
 
-        while(true) {
+        while (true) {
             int req_id = generateNextRequestID();
-
             TypesWriter tw = new TypesWriter();
             tw.writeString(handle, 0, handle.length);
-
             sendMessage(Packet.SSH_FXP_READDIR, req_id, tw.getBytes());
-
             byte[] resp = receiveMessage(34000);
-
             TypesReader tr = new TypesReader(resp);
-
             int t = tr.readByte();
             listener.read(Packet.forName(t));
+            int rep_id = tr.readUINT32();
 
-            int rep_id = tr.readUINT32();
-            if(rep_id != req_id) {
+            if (rep_id != req_id) {
                 throw new RequestMismatchException();
             }
 
-            if(t == Packet.SSH_FXP_NAME) {
+            if (t == Packet.SSH_FXP_NAME) {
                 int count = tr.readUINT32();
-                if(log.isDebugEnabled()) {
+
+                if (log.isDebugEnabled()) {
                     log.debug(String.format("Parsing %d name entries", count));
                 }
-                while(count > 0) {
+
+                while (count > 0) {
                     SFTPv3DirectoryEntry file = new SFTPv3DirectoryEntry();
                     file.filename = tr.readString(this.getCharset());
                     file.longEntry = tr.readString(this.getCharset());
                     listener.read(file.longEntry);
                     file.attributes = new SFTPv3FileAttributes(tr);
-                    if(log.isDebugEnabled()) {
+
+                    if (log.isDebugEnabled()) {
                         log.debug(String.format("Adding file %s", file));
                     }
+
                     files.add(file);
                     count--;
                 }
+
                 continue;
             }
 
-            if(t != Packet.SSH_FXP_STATUS) {
+            if (t != Packet.SSH_FXP_STATUS) {
                 throw new PacketTypeException(t);
             }
 
             int errorCode = tr.readUINT32();
 
-            if(errorCode == ErrorCodes.SSH_FX_EOF) {
+            if (errorCode == ErrorCodes.SSH_FX_EOF) {
                 return files;
             }
+
             String errorMessage = tr.readString();
             listener.read(errorMessage);
             throw new SFTPException(errorMessage, errorCode);
@@ -256,29 +246,24 @@
 
     public final SFTPv3FileHandle openDirectory(String path) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(path, this.getCharset());
-
         sendMessage(Packet.SSH_FXP_OPENDIR, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_HANDLE) {
+        if (t == Packet.SSH_FXP_HANDLE) {
             return new SFTPv3FileHandle(this, tr.readByteString());
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -405,32 +390,26 @@
     @Override
     public SFTPv3FileHandle openFile(String filename, int flags, SFTPFileAttributes attr) throws IOException {
         int req_id = generateNextRequestID();
-
         TypesWriter tw = new TypesWriter();
         tw.writeString(filename, this.getCharset());
         tw.writeUINT32(flags);
-
         tw.writeBytes(attr.toBytes());
-
         sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());
-
         byte[] resp = receiveMessage(34000);
-
         TypesReader tr = new TypesReader(resp);
-
         int t = tr.readByte();
         listener.read(Packet.forName(t));
+        int rep_id = tr.readUINT32();
 
-        int rep_id = tr.readUINT32();
-        if(rep_id != req_id) {
+        if (rep_id != req_id) {
             throw new RequestMismatchException();
         }
 
-        if(t == Packet.SSH_FXP_HANDLE) {
+        if (t == Packet.SSH_FXP_HANDLE) {
             return new SFTPv3FileHandle(this, tr.readByteString());
         }
 
-        if(t != Packet.SSH_FXP_STATUS) {
+        if (t != Packet.SSH_FXP_STATUS) {
             throw new PacketTypeException(t);
         }
 
@@ -443,15 +422,12 @@
     @Override
     public void createSymlink(String src, String target) throws IOException {
         int req_id = generateNextRequestID();
-
         // Changed semantics of src and target. The bug is known on SFTP servers shipped with all
         // versions of OpenSSH (Bug #861).
         TypesWriter tw = new TypesWriter();
         tw.writeString(target, this.getCharset());
         tw.writeString(src, this.getCharset());
-
         sendMessage(Packet.SSH_FXP_SYMLINK, req_id, tw.getBytes());
-
         expectStatusOKMessage(req_id);
     }
 }