Example #1
0
            public void SetLength(long value)
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }

                df.SetLength(start + value);
            }
Example #2
0
        private void InsertValue(String value)
        {
            // The string encoding is fairly simple.  Each short represents a
            // UTF-16 encoded character of the string.  We use 0x0FFFF to represent
            // the string record separator (an invalid UTF-16 character) at the end
            // of the string.  This method will not permit a string to be inserted
            // that contains a 0x0FFFF character.

            // Tell the root set that any child subsets may be dirty
            if (root != this)
            {
                root.version       += 1;
                root.rootStateDirty = true;
            }
            version += 1;

            // If the set is empty, we insert the magic value to the start of the
            // data file and update the internal vars as appropriate
            if (file.Length < 8)
            {
                file.SetLength(8);
                file.Position = 0;
                fileWriter.Write(Magic);
                startPos = 8;
                endPos   = 8;
            }

            int len = value.Length;
            // Make room in the file for the value being inserted
            long strInsertSize = ((long)len * 2) + 2;
            long curPosition   = file.Position;

            file.Shift(strInsertSize);
            // Change the end position
            endPos = endPos + strInsertSize;

            // Insert the characters
            for (int i = 0; i < len; ++i)
            {
                char c = value[i];
                // Check if the character is 0x0FFFF, if it is then generate an error
                if (c == StringDeliminator)
                {
                    // Revert any changes we made
                    file.Position = curPosition + strInsertSize;
                    file.Shift(-strInsertSize);
                    endPos = endPos - strInsertSize;
                    // Throw a runtime exception (don't throw an IO exception because
                    // this will cause a critical stop condition).
                    throw new ApplicationException("Can not encode invalid UTF-16 character 0x0FFFF");
                }
                fileWriter.Write(c);
            }

            // Write the string deliminator
            fileWriter.Write(StringDeliminator);
        }
Example #3
0
 public override void SetLength(long value)
 {
     file.SetLength(value);
 }
Example #4
0
 public void SetLength(long value)
 {
     transaction.CheckValid();
     LogChange();
     parent.SetLength(value);
 }