Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Portions copyright 2006-2009 James Murty. Please see LICENSE.txt
   * for applicable license terms and NOTICE.txt for applicable notices.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
  *
  *  http://aws.amazon.com/apache2.0
  *
  * or in the "license" file accompanying this file. This file 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 com.amazonaws.services.s3.internal;
 
 import java.io.File;
 
 

Deprecated:
by com.amazonaws.internal.ResettableInputStream and this class will be removed in future releases.

A repeatable input stream for files. This input stream can be repeated an unlimited number of times, without any limitation on when a repeat can occur.

 
 public class RepeatableFileInputStream extends SdkInputStream {
     private static final Log log = LogFactory.getLog(RepeatableFileInputStream.class);
 
     private final File file;
     private FileInputStream fis = null;
     private long bytesReadPastMarkPoint = 0;
     private long markPoint = 0;

    
Creates a repeatable input stream based on a file.

Parameters:
file The file from which this input stream reads data.
Throws:
java.io.FileNotFoundException If the specified file doesn't exist, or can't be opened.
 
     public RepeatableFileInputStream(File filethrows FileNotFoundException {
         if (file == null) {
             throw new IllegalArgumentException("File cannot be null");
         }
         this. = new FileInputStream(file);
         this. = file;
     }

    
Returns the File this stream is reading data from.

Returns:
the File this stream is reading data from.
 
     public File getFile() {
         return ;
     }

    
Resets the input stream to the last mark point, or the beginning of the stream if there is no mark point, by creating a new FileInputStream based on the underlying file.

Throws:
java.io.IOException when the FileInputStream cannot be re-created.
 
     @Override
     public void reset() throws IOException {
         this..close();
         abortIfNeeded();
         this. = new FileInputStream();
 
         long skipped = 0;
         long toSkip = ;
         while (toSkip > 0) {
             skipped = this..skip(toSkip);
             toSkip -= skipped;
         }
 
         if (.isDebugEnabled()) {
             .debug("Reset to mark point " + 
                     + " after returning " +  + " bytes");
         }
        this. = 0;
    }
    @Override
    public boolean markSupported() {
        return true;
    }
    @Override
    public void mark(int readlimit) {
        abortIfNeeded();
        this. += ;
        this. = 0;
        if (.isDebugEnabled()) {
            .debug("Input stream marked at " + this. + " bytes");
        }
    }
    @Override
    public int available() throws IOException {
        abortIfNeeded();
        return .available();
    }
    @Override
    public void close() throws IOException {
        .close();
        abortIfNeeded();
    }
    @Override
    public int read() throws IOException {
        abortIfNeeded();
        int byteRead = .read();
        if (byteRead != -1) {
            ++;
            return byteRead;
        } else {
            return -1;
        }
    }
    @Override
    public long skip(long nthrows IOException {
        abortIfNeeded();
        long skipped = .skip(n);
         += skipped;
        return skipped;
    }
    @Override
    public int read(byte[] arg0int arg1int arg2throws IOException {
        abortIfNeeded();
        int count = .read(arg0arg1arg2);
         += count;
        return count;
    }
    @Override
        return ;
    }
New to GrepCode? Check out our FAQ X