Posts

Showing posts with the label flush

Difference Between flush() vs reset() in JAVA

Difference Between flush() vs reset() in JAVA I was just wondering what the difference between flush and reset is? Why is it using reset after flush in example? Why is reset method used if memory cache is wiped by flush method? ObjectOutputStream oos = new ObjectOutputStream(bos); while(true){ oos.writeObject(object); oos.flush(); oos.reset(); object.x++; } 3 Answers 3 Why is reset method used if memory cache is wiped by flush method? flush() will write the buffer of the ObjectOutputStream object in the underlying OutputStream but it will not reset the whole state of the ObjectOutputStream object. flush() ObjectOutputStream OutputStream ObjectOutputStream If you open the ObjectOutputStream source code class, you can see that beyond the buffer it contains many instance fields. Here is a little snippet : ObjectOutputStream /** filter stream for handling block data conversion */...