Volley Source Code Analysis series there for a while, tell me that there are many private messages at the same time that some questions are thrown. For some simple questions, we jumped, and these two days were connected to the question raised by friend @smali. Tell me you're going to have to marvel at the level of detail when viewing the source code, let's think it over.
Q: When writing the file header data, why not write an int directly, but by shifting the way to complete?
Let's take a look at the corresponding source code:
Writeint (OS, cache_magic), static void Writeint (OutputStream os, int n) throws IOException { Os.write ((n >> 0) &A mp 0xFF); Os.write ((n >> 8) & 0xff); Os.write ((n >>) & 0xff); Os.write ((n >>) & 0xff);}
First we know why the output stream itself provides a write (Int) method to pass the shift again?
A: We know that, in fact, for a stream, the data it can manipulate directly is a byte. The root of the problem is the misunderstanding of write (INT) provided by OutputStream. In fact, for OutputStream, when you pass in an int, it truncates the int and gets the low-end byte-length data written to the stream. This means that the data on these bits of 0xffffff00 is lost.
So it can only be written in the form of a shift, or you could calculate a 4 byte array and write it to your stream.
thx~
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
[Android] Volley source code Analysis (children under five years old) Q \ \ u0026 A