comparison src/luan/modules/IoLuan.java @ 1083:e7fb974e0c26

add Io checksum and use it for push
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 21 Nov 2016 22:48:43 -0700
parents 9c13a15a4002
children 27bf094f0ae3
comparison
equal deleted inserted replaced
1082:ece3567d4df5 1083:e7fb974e0c26
223 } catch(FileNotFoundException e) { 223 } catch(FileNotFoundException e) {
224 return false; 224 return false;
225 } 225 }
226 } 226 }
227 227
228 public long checksum() throws IOException, LuanException {
229 long cs = 0;
230 InputStream in = new BufferedInputStream(inputStream());
231 int c;
232 while( (c=in.read()) != -1 ) {
233 cs = 31 * cs + c;
234 }
235 in.close();
236 return cs;
237 }
238
228 public LuanTable table() { 239 public LuanTable table() {
229 LuanTable tbl = new LuanTable(); 240 LuanTable tbl = new LuanTable();
230 try { 241 try {
231 tbl.rawPut( "java", this ); 242 tbl.rawPut( "java", this );
232 tbl.rawPut( "to_string", new LuanJavaFunction( 243 tbl.rawPut( "to_string", new LuanJavaFunction(
247 tbl.rawPut( "read_blocks", new LuanJavaFunction( 258 tbl.rawPut( "read_blocks", new LuanJavaFunction(
248 LuanIn.class.getMethod( "read_blocks", Integer.class ), this 259 LuanIn.class.getMethod( "read_blocks", Integer.class ), this
249 ) ); 260 ) );
250 tbl.rawPut( "exists", new LuanJavaFunction( 261 tbl.rawPut( "exists", new LuanJavaFunction(
251 LuanIn.class.getMethod( "exists" ), this 262 LuanIn.class.getMethod( "exists" ), this
263 ) );
264 tbl.rawPut( "checksum", new LuanJavaFunction(
265 LuanIn.class.getMethod( "checksum" ), this
252 ) ); 266 ) );
253 } catch(NoSuchMethodException e) { 267 } catch(NoSuchMethodException e) {
254 throw new RuntimeException(e); 268 throw new RuntimeException(e);
255 } 269 }
256 return tbl; 270 return tbl;