public void test32BitLittleEndianness() { string tempFile = Path.GetTempFileName(); try { using (FileStream outputStream = File.OpenWrite(tempFile)) { write32BitLittleEndianHeaderToFloatCookie(outputStream); byte[] padding = new byte[24]; outputStream.Write(padding, 0, padding.Length); } using(RRDFile rrdFile = new RRDFile(tempFile)) { Assert.IsFalse(rrdFile.IsBigEndian, "Expected little endian"); Assert.AreEqual(4, rrdFile.Alignment, "Expected 4-byte alignment"); } } finally { try { File.Delete(tempFile); } catch (Exception) { } } }
public void testNoFloatCookie() { string tempFile = Path.GetTempFileName(); try { using (FileStream outputStream = File.OpenWrite(tempFile)) { this.write32BitHeaderToVersion(outputStream); byte[] padding = new byte[24]; outputStream.Write(padding, 0, padding.Length); } using(RRDFile rrdFile = new RRDFile(tempFile)){} } finally { try { File.Delete(tempFile); } catch (Exception) { } } }
internal Header(RRDFile file) { if (file.ReadString(4) != Constants.COOKIE) { throw new IOException("Invalid COOKIE"); } Version = file.ReadString(5); IntVersion = int.Parse(Version); if (IntVersion > 3) { throw new IOException("Unsupported RRD version (" + Version + ")"); } file.Align(); // Consume the FLOAT_COOKIE file.ReadDouble(); DataSourceCount = file.ReadInt(); ArchiveCount = file.ReadInt(); PrimaryDataPointStep = file.ReadInt(); // Skip rest of stat_head_t.par file.Align(); file.SkipBytes(80); size = file.FilePointer - offset; }
internal void LoadCdpStatusBlocks(RRDFile file, int numBlocks) { cdpStatusBlocks = new List<CDPStatusBlock>(); for (int i = 0; i < numBlocks; i++) { cdpStatusBlocks.Add(new CDPStatusBlock(file)); } }
public void testTooShortForHeader() { string tempFile = Path.GetTempFileName(); try { File.WriteAllBytes(tempFile, new byte[1]); using(RRDFile rrdFile = new RRDFile(tempFile)){} } finally { File.Delete(tempFile); } }
public void testReadString() { string tempFile = Path.GetTempFileName(); try { using (FileStream outputStream = File.OpenWrite(tempFile)) { write64BitLittleEndianHeaderToFloatCookie(outputStream); } //The first 4 bytes of the file must be null terminated string "RRD" (Constants.COOKIE) //That's a good enough test using(RRDFile rrdFile = new RRDFile(tempFile)) { String cookie = rrdFile.ReadString(4); Assert.AreEqual(Constants.COOKIE, cookie); } } finally { try { File.Delete(tempFile); } catch (Exception) { } } }
public void testReadInt64BitBigEndian(){ string tempFile = Path.GetTempFileName(); try { using (FileStream outputStream = File.OpenWrite(tempFile)) { write64BitBigEndianHeaderToFloatCookie(outputStream); //Write out 3 integers (the rest of the normal header), each 64 bits, in little endian format. //However, we're expecting only an int (32-bits) back, so the value we're expecting from a // big-endian file is the *last* four bytes only. The first four bytes are ignored. //We write them with real possibly mis-interpretable numbers though, to double check //that it's reading correctly byte[] int1 = { 0x77, 0x66, 0x55, 0x44, 0x78, 0x56, 0x34, 0x12}; byte[] int2 = { 0x77, 0x66, 0x55, 0x44, 0x12, 0x34, 0x56, 0x78}; byte[] int3 = { 0x77, 0x66, 0x55, 0x44, 0x78, 0x12, 0x56, 0x34}; outputStream.Write(int1,0,8); outputStream.Write(int2,0,8); outputStream.Write(int3,0,8); } using(RRDFile rrdFile = new RRDFile(tempFile)) { rrdFile.SkipBytes(24); //Skip the string cookie, version, padding, and float cookie Assert.AreEqual(0x78563412, rrdFile.ReadInt()); Assert.AreEqual(0x12345678, rrdFile.ReadInt()); Assert.AreEqual(0x78125634, rrdFile.ReadInt()); } } finally { try { File.Delete(tempFile); } catch (Exception) { } } }
public void testReadInt64BitLittleEndian(){ string tempFile = Path.GetTempFileName(); try { using (FileStream outputStream = File.OpenWrite(tempFile)) { write64BitLittleEndianHeaderToFloatCookie(outputStream); //Write out 3 integers (the rest of the normal header), each 32 bits, in little endian format. byte[] int1 = {0x12, 0x34, 0x56, 0x78, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x78563412 in little endian byte[] int2 = {0x78, 0x56, 0x34, 0x12, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x12345678 in little endian byte[] int3 = {0x34, 0x12, 0x78, 0x56, 0x77, 0x66, 0x55, 0x44}; //Gives the integer 0x56781234 in little endian outputStream.Write(int1,0,8); outputStream.Write(int2,0,8); outputStream.Write(int3,0,8); } using(RRDFile rrdFile = new RRDFile(tempFile)) { rrdFile.SkipBytes(24); //Skip the string cookie, version, padding, and float cookie Assert.AreEqual(0x78563412, rrdFile.ReadInt()); Assert.AreEqual(0x12345678, rrdFile.ReadInt()); Assert.AreEqual(0x56781234, rrdFile.ReadInt()); } } finally { try { File.Delete(tempFile); } catch (Exception) { } } }
internal void LoadCurrentRow(RRDFile file) { currentRow = file.ReadInt(); }
internal void LoadData(RRDFile file, int dsCount) { dataOffset = file.FilePointer; // Skip over the data to position ourselves at the start of the next archive file.SkipBytes(8*RowCount*dsCount); }