java - How can I implement an OutputStream that I can rewind? -


After writing the output stream can be processed materials, I metadata again and some material from the beginning of the stream again. I am writing the data that is much larger than 4 GB, and it may be written directly to various environmental factors on the basis of the file or an in-memory buffer.

How does the OutputStream allow me to write the header after completing the writing of the content?

Text after "itemprop =" text ">

Random access file output stream here.

Note that if you use it for a large amount of stream output, you can wrap it in temporarily for a BufferedOutputStream avoid very small writing (just abandon the very cover or underlying stream Be sure to flush it before using it directly).

Import java.io. *; / ** * An embedded file output stream. * & Lt; P & gt; * Threading Design: [x] single-threaded [] Threadsafe [] irreversible [] isolated * / public class RandomFileOutputStream extends OutputStream {// ********************** **************************************************************************************************** ***** // Institute Properties / ********************************************************************************************* *************************************************************************************************** **************************************************************************************************** ****** Secure RandomAccessFile Random file; // Writing a random file to save boolean sync; // What to sync every script / / *************************************** *************************** *********************** ************ // Example creation / INITIALIZATON / finalization, opening / closing // ******************* ****************************** ******************** ******* Public RandomFileOutputStream (string FNM) throws IOException {This (FNM, False); } Public RandomFileOutputStream (string FN, Boolean sync) throws IOException {This (new file (FNM), syn); } Public RandomFileOutputStream (file file) throws IOException {this (fil, false); } Public RandomFileOutputStream (file file, Boolean sync) throws IOException {super (); File equivalent; // Original file fil = fil.getAbsoluteFile (); If ((par = fil.getParentFile ()) = null) {IoUtil.createDir (equal); } RandomFile = New RandomAccessFile (fil, "rw"); Sync = syn; } // *********************************************************************************************** **************************************************************************************************** ***************************** // instance methods - output stream implementation // ********** **************************************************************************************************** **************************************************************************************************** **************************************************************************************************** *************** I Sync (); }} Write public null (byte [] val) throws IOException {randomFile.write (val); If (sync) {randomFile.getFD (.) Sync (); }} Public void write (byte [] val, int off, int len) IOException Throws {randomFile.write (val, off, len); If (sync) {randomFile.getFD (.) Sync (); }} Public Zero Flush () throws IOException {if (sync) {randomFile.getFD (.). Sync (); }} Public Zero Closure () throws IOException {randomFile.close (); } // *********************************************** *************************************************************************************************** ********************* installation methods - Random access extension // ********** *********** *************************************** I} public void Setfailpointr (long) IOException Throws {randomFile.seek (pos); } Get Public Long Live File Sections () throws IOException {random returnFile.length (); } Public Zero Setfile size (Longer) throws IOException {randomFile.setLength (len); } Public file descriptor getFD () throws IOException {return randomFile.getFD (); }} // END public class

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -