I’m reading in a file with an InputStream to a byte array, and then changing each byte into an int. Then I store the int into another array. Is there a way to make this more efficient? Specifically, is there a way to use only one array instead of two? Allocating both of the arrays is taking too long for my program.
This is what I am doing right now (is is the InputStream):
byte[] a = new byte[num];
int[] b = new int[num];
try {
is.read(a, 0, num);
for (int j = 0; j < nPixels; j++) {
b[j] = (int) a[j] & 0xFF; //converting from a byte to an "unsigned" int
}
} catch (IOException e) { }
Lets see… you can’t read int’s directly since that will try to read 4 bytes at a time. You could say
inside the loop if you’re ok with reading the stream one byte at a time.