~binwiederhier/syncany/newsync

« back to all changes in this revision

Viewing changes to syncany/syncany-core/src/main/java/org/syncany/experimental/chunking/FixedOffsetChunker.java

  • Committer: Philipp Heckel
  • Date: 2011-07-24 21:15:41 UTC
  • Revision ID: philipp.heckel@gmail.com-20110724211541-sgxf25p2tijj4b07
chunking experiments

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    }
54
54
  
55
55
    @Override
56
 
    public Enumeration<Chunk> createChunks(File file) throws FileNotFoundException {
57
 
        return new FixedChunkEnumeration(file);
 
56
    public Enumeration<Chunk> createChunks(InputStream in) throws IOException {
 
57
        return new FixedChunkEnumeration(in);
58
58
    }
59
59
 
60
60
    public class FixedChunkEnumeration implements Enumeration<Chunk> {
61
 
        private InputStream fis;           
 
61
        private InputStream in;           
62
62
        private byte[] buffer;
63
63
        private boolean closed;
64
64
        
65
 
        public FixedChunkEnumeration(File file) throws FileNotFoundException {
66
 
            this.fis = new FileInputStream(file);
 
65
        public FixedChunkEnumeration(InputStream in) {
 
66
            this.in = in;
67
67
            this.buffer = new byte[chunkSize];
68
68
            this.closed = false;
69
69
        }
76
76
            
77
77
            try {
78
78
                //System.out.println("fis ="+fis.available());
79
 
                return fis.available() > 0;
 
79
                return in.available() > 0;
80
80
            }
81
81
            catch (IOException ex) {
82
82
                if (logger.isLoggable(Level.WARNING)) {
90
90
        @Override
91
91
        public Chunk nextElement() {    
92
92
            try {
93
 
                int read = fis.read(buffer);
 
93
                int read = in.read(buffer);
94
94
                
95
95
                if (read == -1) {
96
96
                    return null;
97
97
                }
98
98
                
99
99
                // Close if this was the last bytes
100
 
                if (fis.available() == 0) {
101
 
                    fis.close();
 
100
                if (in.available() == 0) {
 
101
                    in.close();
102
102
                    closed = true;
103
103
                }
104
104