1 28 29 package com.caucho.vfs; 30 31 import com.caucho.util.Crc64; 32 33 import java.io.IOException ; 34 35 public class Crc64Stream extends StreamImpl { 36 private StreamImpl _next; 37 private long _crc; 38 39 public Crc64Stream(StreamImpl next) 40 { 41 _next = next; 42 } 43 44 public Crc64Stream() 45 { 46 } 47 48 51 public void init(StreamImpl next) 52 { 53 _next = next; 54 _crc = 0; 55 } 56 57 60 public long getCRC() 61 { 62 return _crc; 63 } 64 65 68 public boolean canRead() 69 { 70 return _next.canRead(); 71 } 72 73 74 81 public int read(byte []buffer, int offset, int length) 82 throws IOException 83 { 84 long crc = _crc; 85 86 int len = _next.read(buffer, offset, length); 87 88 for (int i = 0; i < len; i++) 89 crc = Crc64.next(crc, buffer[offset + i]); 90 91 _crc = crc; 92 93 return len; 94 } 95 96 99 public boolean canWrite() 100 { 101 return _next.canWrite(); 102 } 103 104 105 113 public void write(byte []buffer, int offset, int length, boolean isEnd) 114 throws IOException 115 { 116 long crc = _crc; 117 118 for (int i = 0; i < length; i++) 119 crc = Crc64.next(crc, buffer[offset + i]); 120 121 _crc = crc; 122 123 _next.write(buffer, offset, length, isEnd); 124 } 125 126 129 public void clearWrite() 130 { 131 _next.clearWrite(); 132 } 133 134 137 public void flush() throws IOException 138 { 139 _next.flush(); 140 } 141 142 145 public void closeWrite() throws IOException 146 { 147 _next.closeWrite(); 148 } 149 150 153 public Path getPath() 154 { 155 return _next.getPath(); 156 } 157 158 161 public void setPath(Path path) 162 { 163 _next.setPath(path); 164 } 165 166 169 public void close() throws IOException 170 { 171 _next.close(); 172 } 173 } 174 | Popular Tags |