public PersistentNextSpaceArray(String arrayName, int elementSize, int userHeaderSize) { if (elementSize <= 0) throw new InvalidElementSizeException("The element size must be greater than zero"); if(userHeaderSize < 0) throw new InvalidUserHeaderException("User Header size must be positive"); _fileWithHeader = new FileWithHeader(arrayName, userHeaderSize + GetElementSizeSize()); PutElementSize(elementSize); PutUserHeader(new byte[0]); }
public void FileAlreadyExistsTest() { string fileName = "AlreadyExists"; FileWithHeader fwh = InitFWH(fileName, 5); FileWithHeader fwh2 = null; try { fwh2 = new FileWithHeader(fileName, 5); Assert.Fail("Should throw exception"); } catch (FileNameConflictException) { } finally { fwh.Close(); if (fwh2 != null) //if for some reason it actuall worked, fwh2.Close(); // still close the file } }
public PersistentNextSpaceArray(String arrayName) { _fileWithHeader = new FileWithHeader(arrayName); byte[] userHeaderBytes = _fileWithHeader.GetUserHeader(); }
private static void GetPutTestAssert(byte expectedValue, int expectedIndex, FileWithHeader target) { int nextIndexBefore = target.GetNextIndex(); target.Put(expectedIndex, expectedValue); if (expectedIndex >= nextIndexBefore) Assert.AreEqual(expectedIndex+1, target.GetNextIndex()); Assert.AreEqual(expectedValue, target.Get(expectedIndex)); }
private static void GetRangeTestAssert(byte[] bytes, int startIndex, FileWithHeader fwh) { fwh.Put(startIndex, bytes); byte[] actual = fwh.GetRange(startIndex, startIndex+bytes.Length - 1); TestHelper.AssertByteArraysAreSame(bytes, actual); }
private static void GetPutArrayTestAssert(FileWithHeader fwh, int index, byte[] data) { int nextIndexBefore = fwh.GetNextIndex(); fwh.Put(index, data); if(index+data.Length >= nextIndexBefore) Assert.AreEqual(index+data.Length, fwh.GetNextIndex()); byte[] actual = fwh.GetAmount(index, data.Length); TestHelper.AssertByteArraysAreSame(data, actual); }
public void ReopenTest() { string fileName = "ReopenFileWithHeaderTest"; FileWithHeader fwh = InitFWH(fileName, 5); try { //write values int expectedIndex1 = 0; byte expectedValue1 = 6; fwh.Put(expectedIndex1, expectedValue1); int expectedIndex2 = 55; byte expectedValue2 = 200; fwh.Put(expectedIndex2, expectedValue2); //get next index int expectedNextIndex = fwh.GetNextIndex(); byte[] expectedUserHeader = new byte[5]{1,2,3,4,5}; fwh.PutUserHeader(expectedUserHeader); fwh.Close(); fwh = new FileWithHeader(fileName); Assert.AreEqual(expectedValue1, fwh.Get(expectedIndex1)); Assert.AreEqual(expectedValue2, fwh.Get(expectedIndex2)); Assert.AreEqual(expectedNextIndex, fwh.GetNextIndex()); TestHelper.AssertByteArraysAreSame(expectedUserHeader, fwh.GetUserHeader()); } finally { fwh.Close(); } }
public FileWithHeader InitFWH(string fileName, int userHeaderSize) { FileWithHeader fwh; try { fwh = new FileWithHeader(fileName, userHeaderSize); } catch (FileNameConflictException) { fwh = new FileWithHeader(fileName); fwh.Delete(); fwh = new FileWithHeader(fileName, userHeaderSize); } return fwh; }
public PersistentHeap(String heapName) { _file = new FileWithHeader(heapName); }
public PersistentHeap(String heapName, int userHeaderSize) { _file = new FileWithHeader(heapName, userHeaderSize + GetFreeSpaceHeadSize()); PutFreeSpaceHead(FreeLinkedListNullPointer); }