Deveel.Data.Store.ObjectStore.CreateNewObject C# (CSharp) Method

CreateNewObject() public method

public CreateNewObject ( long maxSize, bool compressed ) : ILargeObject
maxSize long
compressed bool
return ILargeObject
        public ILargeObject CreateNewObject(long maxSize, bool compressed)
        {
            if (maxSize < 0)
                throw new IOException("Negative object size not allowed.");

            try {
                store.Lock();

                // Allocate the area (plus header area) for storing the blob pages
                long pageCount = ((maxSize - 1) / (PageSize * 1024)) + 1;
                IArea objArea = store.CreateArea((pageCount * 8) + 32);
                long objAreaId = objArea.Id;

                var type = 2;			// Binary Type
                if (compressed)
                    type |= CompressedFlag;

                // Set up the area header
                objArea.WriteInt4(0);           // Reserved for future
                objArea.WriteInt4(type);
                objArea.WriteInt8(maxSize);
                objArea.WriteInt8(0);
                objArea.WriteInt8(pageCount);

                // Initialize the empty blob area
                for (long i = 0; i < pageCount; ++i) {
                    objArea.WriteInt8(-1);
                }

                // And finish
                objArea.Flush();

                // Update the fixed_list and return the record number for this blob
                long refId = AddToRecordList(objAreaId);
                return new LargeObject(this, refId, maxSize, 0, compressed, false);
            } finally {
                store.Unlock();
            }
        }