private DataOutputStream getDataStream ( int keyLength ) throws IOException { // Resize array if necessary if ( dataStreams . length <= keyLength ) { dataStreams = Arrays . copyOf ( dataStreams , keyLength + 1 ) ; dataFiles = Arrays . copyOf ( dataFiles , keyLength + 1 ) ; } DataOutputStream dos = dataStreams [ keyLength ] ; if ( dos == null ) { File file = new File ( tempFolder , "data" + keyLength + ".dat" ) ; file . deleteOnExit ( ) ; dataFiles [ keyLength ] = file ; dos = new DataOutputStream ( new BufferedOutputStream ( new FileOutputStream ( file ) ) ) ; dataStreams [ keyLength ] = dos ; // Write one byte so the zero offset is reserved dos . writeByte ( 0 ) ; } return dos ; }
Get the data stream for the specified keyLength create it if needed