通常のエンドユーザーが一部のファイルに簡単にアクセスできないように、単純な種類の暗号化を行う必要があります。
FileInputStream によって読み取られるファイルは、html ファイル、png、jpeg、およびさまざまな単純なテキスト ファイル (javascript、xml など) です。
私が現在していることはこれです:
public static byte[] toEncryptedByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output, true);
return output.toByteArray();
}
public synchronized static final int copy(final InputStream input, final OutputStream output, final boolean modify) throws IOException {
if (input == null || output == null) {
throw new IOException("One stream is null!");
}
byte[] mBuffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int n;
while ((n = input.read(mBuffer)) != -1) {
if (modify) {
for ( int i = 0 ; i < n ; i++ ) {
mBuffer[i] = (byte) ~mBuffer[i]; // byte manipulation
}
}
output.write(mBuffer, 0, n);
output.flush();
count += n;
}
mBuffer = null;
return count;
}
メモリに完全なバイト配列があるため、メモリ フットプリントは非常に大きくなります (メモリ内に 2 MB を超えるビットマップについて話します)。
FileInputStream クラスを単純に拡張して、ファイルの内容を読み取りながらバイト操作を行うことができると考えました。Bitmap.decodeStream(inputstream)
ビットマップを取得するためにバイト配列を作成する代わりに使用できるので、メモリ使用量を減らすことができます...しかし、ここでは完全に立ち往生しています。read()
メソッドとメソッドはネイティブであるため、readBytes(...)
オーバーライドできません。
私の闇に光を広げてください...