From 9d754445529cf37a654361e8995b904b78e2e1a0 Mon Sep 17 00:00:00 2001 From: pelya Date: Fri, 20 Aug 2010 19:05:31 +0300 Subject: [PATCH] Added some CRC checks to data downloader --- project/src/DataDownloader.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/project/src/DataDownloader.java b/project/src/DataDownloader.java index d7773d818..7aef12fc1 100644 --- a/project/src/DataDownloader.java +++ b/project/src/DataDownloader.java @@ -286,11 +286,22 @@ class DataDownloader extends Thread } out.flush(); out.close(); + out = null; } catch( java.io.IOException e ) { Status.setText( "Error writing file " + path ); return; } - + + try { + CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() ); + while( check.read(buf, 0, buf.length) > 0 ) {}; + if( check.getChecksum().getValue() != entry.getCrc() ) + throw new Exception(); + } catch( Exception e ) + { + Status.setText( "CRC32 check failed for file " + path ); + return; + } } OutputStream out = null;