Web上でxmlファイルを取得し、Blackberry電話のSDカードに保存するアプリケーションを作成する必要があります。xmlファイルはcronジョブによって更新されます。したがって、データがこのxmlファイルに追加されている場合は、アプリケーションに新しいxmlファイルをダウンロードしてもらいたいと思います。
今のところ、このコードを使用してすべてのデータファイルを比較します
public static boolean isSame( DataInputStream input1, DataInputStream input2 ) throws IOException {
boolean error = false;
try {
byte[] buffer1 = new byte[1024];
byte[] buffer2 = new byte[1024];
try {
int numRead1 = 0;
int numRead2 = 0;
while (true) {
numRead1 = input1.read(buffer1);
numRead2 = input2.read(buffer2);
if (numRead1 > -1) {
if (numRead2 != numRead1) return false;
// Otherwise same number of bytes read
if (!Arrays.equals(buffer1, buffer2)) return false;
// Otherwise same bytes read, so continue ...
} else {
// Nothing more in stream 1 ...
return numRead2 < 0;
}
}
} finally {
input1.close();
}
} catch (IOException e) {
error = true; // this error should be thrown, even if there is an error closing stream 2
throw e;
} catch (RuntimeException e) {
error = true; // this error should be thrown, even if there is an error closing stream 2
throw e;
} finally {
try {
input2.close();
} catch (IOException e) {
if (!error) throw e;
}
}
}
完全に機能しますが、実行に時間がかかります。
それで、ファイルの終わりを読んで、変更が加えられたかどうかを確認し、変更が加えられた場合は、それを再ダウンロードすることは可能ですか?