Example #1
0
        /// <summary>
        /// Adds the record and returns the starting offset and number of bytes written.
        /// </summary>
        /// <param name="record"></param>
        /// <param name="dataFileOffset"></param>
        /// <param name="dataSizeBytes"></param>
        /// <returns></returns>
        public bool Append(VariableLengthRecord record, ref int dataFileOffset, ref int dataSizeBytes)
        {
            try
            {
                dataFileOffset = (int)mFileStream.length();
                mFileStream.seek(dataFileOffset);                 // Seek to the end of the file

                dataSizeBytes = record.Serialize(mFileStream);    // Convert the record to the stream
                mBytesUsed   += dataSizeBytes;

                mFileStream.seek(0);
                mFileStream.writeInt(mBytesUsed);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #2
0
        public VariableLengthRecordFile(String folder, String filename)
        {
            mPathname  = folder;
            mPathname += ("/");
            mPathname += (filename);
            mPathname += (".dat");

            mFileStream = new RandomAccessFile(mPathname);
            if (mFileStream.length() > 0)
            {
                mFileStream.seek(0);
                mBytesUsed = mFileStream.readInt();
            }
            else
            {
                mBytesUsed = 0;
                mFileStream.writeInt(mBytesUsed);
            }
        }