Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
java.io.InputStream
public abstract int read() throws IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
java.lang.Byte
MAX_VALUE A constant holding the maximum value a byte can have, 2^7-1
MIN_VALUE A constant holding the minimum value a byte can have, -2^7.
int odin = 2; — как один тут товарищ писал, это странно, да :)"true".equals(str)label.equals(str)Objects.equal(str, "true") из GuavaStringUtils.equals(str, "true") из commons langpublic static void main(String args[]) throws IOException {
//~5mb
File file = new File("D:\\P1010387.jpg");
readFile(new BufferedInputStream(new FileInputStream(file)), "Buffered");
readFile(new FileInputStream(file), "Not buffered");
}
private static void readFile(InputStream is, String type) throws IOException {
System.out.println(type);
System.out.println("Start : " + new Date());
int val = 0;
while ((val = is.read()) != -1) {
val = val + 1;
}
System.out.println("End : " + new Date());
}
Правда, в этом случае есть один большой минус — стоимость поддержки приложения увеличивается, особенно это становится заметным, когда нужно добавить, удалить или изменить одно из существующих состояний.
В дополнение — постоянно при добавлении вычисляется хеш, который для сложных обьектов может стоить дороговато.
Маленькие хитрости Java. Часть 2