Closed AndroidDeveloperLB closed 4 years ago
while ( (bytesRead = i.read(...)) != -1)
insteadBut in any case, please don't put this whole code in a CTOR...
Thank you.
The CTOR is useless now though. You can make it private to tell whoever that use it : "this is not intended to be used this way" .
And you can apply the suggestion of renaming to IOException ignored
and remove the casting of long opsLimit = (long) byteToInt(getBytes(i, 8));
I also don't see that you use getHex
function. What was it used for? To investigate how it works?
Fixed to all three of the above points!
Yep, I was using it mostly to debug the outputs of the crypto byte arrays when putting the whole thing together, have left it in just in case it's useful for anyone else (and me later if I need to debug it again).
I see. Now it has those stuff though:
FileOutputStream fos = null;
Not used in decryptFile.
byte[] data = new byte[(int) num];
"num" is already an int.
copyInputStreamToFile
- I think you could use try-with, like here:
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
Meaning maybe like this:
try (OutputStream out = new FileOutputStream(file)) {
// no need to close it. It auto-closes in "finally" for you, even if "finally" isn't written by you
} catch (Exception e) {
e.printStackTrace();
}
Thanks, have fixed the above!
Thank you. If you wish, you can also apply this:
And it's a common thing to put constants at the top, at least on Java. On Kotlin sadly it's usually at the bottom :(
Have done! :)
Seems all the nice warnings are gone. Only thing that's left is this one, as you don't really need to initialize it.
int bytesRead = 0;
You could, however, put "final" for each variable, whenever you can. If you used Kotlin, the IDE would have helped you on this. Back in the days of Eclipse, it had such a suggestion for Java, and even did it for you each time you've formatted the code (optional setting).
This :
A byte can't be larger... The condition is useless.
This:
No reason to check twice. The condition is enough. You can use
while(true)
instead.You can use this instead:
It's already not null. Also, it's recommended to close it in the finally-block, or better: using "try(...)" on it, to auto-close it, as if it's in the finally-block.
On Java, functions are supposed to start with lower-case letter. Meaning: