/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.commons.net.ssh.sftp;

import java.io.IOException;
import java.io.InputStream;

public class RemoteFileInputStream extends InputStream
{
    
    private final RemoteFile rf;
    private final byte[] b = new byte[1];
    private long fileOffset = 0;
    
    public RemoteFileInputStream(RemoteFile rf)
    {
        this.rf = rf;
    }
    
    public RemoteFileInputStream(RemoteFile rf, int fileOffset)
    {
        this(rf);
        this.fileOffset = fileOffset;
    }
    
    public void seek(long fileOffset)
    {
        this.fileOffset = fileOffset;
    }
    
    @Override
    public int read() throws IOException
    {
        return read(b, 0, 1) == -1 ? -1 : b[0];
    }
    
    @Override
    public int read(byte[] into, int off, int len) throws IOException
    {
        int read = rf.read(fileOffset, into, off, len);
        if (read != -1)
            fileOffset += read;
        return read;
    }
    
}

@@ -984,23 +984,37 @@
 nal 
-RemoteFile rf
+byte%5B%5D b = new byte%5B1%5D
 ;%0A
+    %0A
     
@@ -1027,39 +1027,35 @@
 e final 
-byte%5B%5D b = new byte%5B1%5D;
+RemoteFile rf;%0A    
 %0A    pri
@@ -1078,12 +1078,62 @@
 fset
- = 0
+;%0A    private long markPos;%0A    private long readLimit
 ;%0A  
@@ -1205,16 +1205,15 @@
 this
-.rf = rf
+(rf, 0)
 ;%0A  
@@ -1307,12 +1307,16 @@
 this
-(rf)
+.rf = rf
 ;%0A  
@@ -1370,41 +1370,389 @@
     
-public void seek(long fileOffset)
+@Override%0A    public boolean markSupported()%0A    %7B%0A        return true;%0A    %7D%0A    %0A    @Override%0A    public void mark(int readLimit)%0A    %7B%0A        this.readLimit = readLimit;%0A        markPos = fileOffset;%0A    %7D%0A    %0A    @Override%0A    public void reset() throws IOException%0A    %7B%0A        fileOffset = markPos;%0A    %7D%0A    %0A    @Override%0A    public long skip(long n) throws IOException
 %0A   
@@ -1754,32 +1754,40 @@
 n%0A    %7B%0A        
+return (
 this.fileOffset 
@@ -1780,32 +1780,41 @@
 is.fileOffset = 
+Math.min(
 fileOffset;%0A    
@@ -1799,32 +1799,51 @@
 h.min(fileOffset
+ + n, rf.length()))
 ;%0A    %7D%0A    %0A   
@@ -2129,16 +2129,26 @@
  != -1)%0A
+        %7B%0A
         
@@ -2167,24 +2167,141 @@
 et += read;%0A
+            if (markPos != 0 && read %3E readLimit) // Invalidate mark position%0A                markPos = 0;%0A        %7D%0A
         retu

make sftp RemoteFileInputStream more full-fledged