Logo Search packages:      
Sourcecode: jenkins-trilead-ssh2 version File versions  Download package

int com::trilead::ssh2::SFTPv3Client::read ( SFTPv3FileHandle  handle,
long  fileOffset,
byte[]  dst,
int  dstoff,
int  len 
) throws IOException [inline]

Read bytes from a file. No more than 32768 bytes may be read at once. Be aware that the semantics of read() are different than for Java streams.

  • The server will read as many bytes as it can from the file (up to len), and return them.
  • If EOF is encountered before reading any data, -1 is returned.
  • If an error occurs, an exception is thrown.
  • For normal disk files, it is guaranteed that the server will return the specified number of bytes, or up to end of file. For, e.g., device files this may return fewer bytes than requested.
handlea SFTPv3FileHandle handle
fileOffsetoffset (in bytes) in the file
dstthe destination byte array
dstoffoffset in the destination byte array
lenhow many bytes to read, 0 < len <= 32768 bytes
the number of bytes that could be read, may be less than requested if the end of the file is reached, -1 is returned in case of EOF

Definition at line 1228 of file SFTPv3Client.java.

References receiveMessage().

Referenced by writeToFile().


            if ((len > 32768) || (len <= 0))
                  throw new IllegalArgumentException("invalid len argument");

            int req_id = generateNextRequestID();

            TypesWriter tw = new TypesWriter();
            tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);

            if (debug != null)
                  debug.println("Sending SSH_FXP_READ...");

            sendMessage(Packet.SSH_FXP_READ, req_id, tw.getBytes());

            byte[] resp = receiveMessage(34000);

            TypesReader tr = new TypesReader(resp);

            int t = tr.readByte();

            int rep_id = tr.readUINT32();
            if (rep_id != req_id)
                  throw new IOException("The server sent an invalid id field.");

            if (t == Packet.SSH_FXP_DATA)
                  if (debug != null)
                        debug.println("Got SSH_FXP_DATA...");

                  int readLen = tr.readUINT32();

                  if ((readLen < 0) || (readLen > len))
                        throw new IOException("The server sent an invalid length field.");

                  tr.readBytes(dst, dstoff, readLen);

                  return readLen;

            if (t != Packet.SSH_FXP_STATUS)
                  throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");

            int errorCode = tr.readUINT32();

            if (errorCode == ErrorCodes.SSH_FX_EOF)
                  if (debug != null)
                        debug.println("Got SSH_FX_EOF.");

                  return -1;

            String errorMessage = tr.readString();

            throw new SFTPException(errorMessage, errorCode);

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index