// pack single image file into a .pdb file: public void PackImageIntoPdb(string name, string srcFilePath, string pdbFilePath, int format) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); // images: ArrayList files = new ArrayList(); // of FileInfo of .bmp or .jpg files ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp or .jpg files involved ArrayList cntFormats = new ArrayList(); // of int, just one counter at the end of pdb int maxFileLength = makeSingleImageArray(files, fileLengths, srcFilePath); cntFormats.Add(2); // just one ushort format indicator at the end of pdb int recCount = fileLengths.Count + cntFormats.Count; // make and write header: PDBHeader header = new PDBHeader(name, recCount); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, fileLengths, recCount, true, false); // start writing header.writeLocators(fsOut, cntFormats, 0, false, true); // continue writing, finish with alignment // write actual records as length-specified strings (image name), followed by raw bmp data: byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name int length = 0; for (int i = 0; i < files.Count; i++) { FileInfo fi = (FileInfo)files[i]; string imageName = fi.Name; length = ByteWriter.writeString(buffer, 0, imageName); fsOut.Write(buffer, 0, length); FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); length = fs.Read(buffer, 0, (int)fi.Length); fs.Close(); fsOut.Write(buffer, 0, length); } // write the number of image files inside the pdb as the last record: length = ByteWriter.writeUshort(buffer, 0, (ushort)format); fsOut.Write(buffer, 0, length); fsOut.Close(); }
/* // create a .pdb file from text, broken into chunks of reasonable size to fit into 32kb/record limitation: public void MakeTextPdb(string name, int linesPerChunk, TextReader textReader, string pdbFilePath) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); ArrayList chunks = new ArrayList(); // of string ArrayList chunkLengths = new ArrayList(); // of int, with 2 added for string length // make chunks of no more than LINES_PER_CHUNK lines and count them: int maxChunkLength = makeChunks(linesPerChunk, chunks, chunkLengths, textReader); // make and write header: PDBHeader header = new PDBHeader(name, chunks.Count); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, chunkLengths, chunkLengths.Count, true, true); // write actual records as length-specified strings: byte[] buffer = new Byte[maxChunkLength + 2 + 4]; // 2 bytes for length, up to 4 for padding for(int i=0; i < chunks.Count ;i++) { string _chunk = (string)chunks[i]; int length = ByteWriter.writeString (buffer, 0, _chunk); fsOut.Write(buffer, 0, length); } fsOut.Close(); } // pack all .bmp files from specified folder into a .pdb file: public void PackImagesIntoPdb(string name, string srcFolderPath, string pdbFilePath) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); ArrayList files = new ArrayList(); // of FileInfo of .bmp files ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp files involved int maxFileLength = makeImageArray(files, fileLengths, srcFolderPath); // make and write header: PDBHeader header = new PDBHeader(name, files.Count); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, fileLengths, fileLengths.Count, true, true); // write actual records as length-specified strings (image name), followed by raw bmp data: byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name for(int i=0; i < files.Count ;i++) { FileInfo fi = (FileInfo)files[i]; string imageName = fileNamePrefix + fi.Name; int length = ByteWriter.writeString (buffer, 0, imageName); fsOut.Write(buffer, 0, length); FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); length = fs.Read(buffer, 0, (int)fi.Length); fs.Close(); fsOut.Write(buffer, 0, length); } fsOut.Close(); } */ // pack all .bmp files from specified folder, and the descr file into a .pdb file: public void PackImagesAndDescrIntoPdb(string name, string srcFolderPath, string pdbFilePath, int linesPerChunk, TextReader textReader) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); // images: ArrayList files = new ArrayList(); // of FileInfo of .bmp or .jpg files ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp or .jpg files involved // descr: ArrayList chunks = new ArrayList(); // of string ArrayList chunkLengths = new ArrayList(); // of int, with 2 added for string length ArrayList cntLengths = new ArrayList(); // of int, just one counter at the end of pdb int maxFileLength = makeImageArray(files, fileLengths, srcFolderPath); // make chunks of no more than LINES_PER_CHUNK lines and count them: int maxChunkLength = makeChunks(linesPerChunk, chunks, chunkLengths, textReader); cntLengths.Add(2); // just one ushort counter at the end of pdb int recCount = fileLengths.Count + chunkLengths.Count + cntLengths.Count; // make and write header: PDBHeader header = new PDBHeader(name, recCount); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, fileLengths, recCount, true, false); // start writing header.writeLocators(fsOut, chunkLengths, 0, false, false); // continue writing header.writeLocators(fsOut, cntLengths, 0, false, true); // continue writing, finish with alignment // write actual records as length-specified strings (image name), followed by raw bmp data: byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name int length = 0; for(int i=0; i < files.Count ;i++) { FileInfo fi = (FileInfo)files[i]; string imageName = fileNamePrefix + fi.Name; length = ByteWriter.writeString (buffer, 0, imageName); fsOut.Write(buffer, 0, length); FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); length = fs.Read(buffer, 0, (int)fi.Length); fs.Close(); fsOut.Write(buffer, 0, length); } // write actual records as length-specified strings: buffer = new Byte[maxChunkLength + 2 + 4]; // 2 bytes for length, up to 4 for padding for(int i=0; i < chunks.Count ;i++) { string _chunk = (string)chunks[i]; length = ByteWriter.writeString (buffer, 0, _chunk); fsOut.Write(buffer, 0, length); } // write the number of image files inside the pdb as the last record: length = ByteWriter.writeUshort (buffer, 0, (ushort)files.Count); fsOut.Write(buffer, 0, length); fsOut.Close(); }
/* * // create a .pdb file from text, broken into chunks of reasonable size to fit into 32kb/record limitation: * public void MakeTextPdb(string name, int linesPerChunk, TextReader textReader, string pdbFilePath) * { * FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); * * ArrayList chunks = new ArrayList(); // of string * ArrayList chunkLengths = new ArrayList(); // of int, with 2 added for string length * * // make chunks of no more than LINES_PER_CHUNK lines and count them: * int maxChunkLength = makeChunks(linesPerChunk, chunks, chunkLengths, textReader); * * // make and write header: * PDBHeader header = new PDBHeader(name, chunks.Count); * header.writeHeader(fsOut); * * // now write record locators, 8 bytes per each record, containing offsets of actual records: * header.writeLocators(fsOut, chunkLengths, chunkLengths.Count, true, true); * * // write actual records as length-specified strings: * byte[] buffer = new Byte[maxChunkLength + 2 + 4]; // 2 bytes for length, up to 4 for padding * for(int i=0; i < chunks.Count ;i++) * { * string _chunk = (string)chunks[i]; * int length = ByteWriter.writeString (buffer, 0, _chunk); * fsOut.Write(buffer, 0, length); * } * fsOut.Close(); * } * * // pack all .bmp files from specified folder into a .pdb file: * public void PackImagesIntoPdb(string name, string srcFolderPath, string pdbFilePath) * { * FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); * * ArrayList files = new ArrayList(); // of FileInfo of .bmp files * ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp files involved * * int maxFileLength = makeImageArray(files, fileLengths, srcFolderPath); * * // make and write header: * PDBHeader header = new PDBHeader(name, files.Count); * header.writeHeader(fsOut); * * // now write record locators, 8 bytes per each record, containing offsets of actual records: * header.writeLocators(fsOut, fileLengths, fileLengths.Count, true, true); * * // write actual records as length-specified strings (image name), followed by raw bmp data: * byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name * for(int i=0; i < files.Count ;i++) * { * FileInfo fi = (FileInfo)files[i]; * string imageName = fileNamePrefix + fi.Name; * int length = ByteWriter.writeString (buffer, 0, imageName); * fsOut.Write(buffer, 0, length); * FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); * length = fs.Read(buffer, 0, (int)fi.Length); * fs.Close(); * fsOut.Write(buffer, 0, length); * } * fsOut.Close(); * } */ // pack all .bmp files from specified folder, and the descr file into a .pdb file: public void PackImagesAndDescrIntoPdb(string name, string srcFolderPath, string pdbFilePath, int linesPerChunk, TextReader textReader) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); // images: ArrayList files = new ArrayList(); // of FileInfo of .bmp or .jpg files ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp or .jpg files involved // descr: ArrayList chunks = new ArrayList(); // of string ArrayList chunkLengths = new ArrayList(); // of int, with 2 added for string length ArrayList cntLengths = new ArrayList(); // of int, just one counter at the end of pdb int maxFileLength = makeImageArray(files, fileLengths, srcFolderPath); // make chunks of no more than LINES_PER_CHUNK lines and count them: int maxChunkLength = makeChunks(linesPerChunk, chunks, chunkLengths, textReader); cntLengths.Add(2); // just one ushort counter at the end of pdb int recCount = fileLengths.Count + chunkLengths.Count + cntLengths.Count; // make and write header: PDBHeader header = new PDBHeader(name, recCount); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, fileLengths, recCount, true, false); // start writing header.writeLocators(fsOut, chunkLengths, 0, false, false); // continue writing header.writeLocators(fsOut, cntLengths, 0, false, true); // continue writing, finish with alignment // write actual records as length-specified strings (image name), followed by raw bmp data: byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name int length = 0; for (int i = 0; i < files.Count; i++) { FileInfo fi = (FileInfo)files[i]; string imageName = fileNamePrefix + fi.Name; length = ByteWriter.writeString(buffer, 0, imageName); fsOut.Write(buffer, 0, length); FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); length = fs.Read(buffer, 0, (int)fi.Length); fs.Close(); fsOut.Write(buffer, 0, length); } // write actual records as length-specified strings: buffer = new Byte[maxChunkLength + 2 + 4]; // 2 bytes for length, up to 4 for padding for (int i = 0; i < chunks.Count; i++) { string _chunk = (string)chunks[i]; length = ByteWriter.writeString(buffer, 0, _chunk); fsOut.Write(buffer, 0, length); } // write the number of image files inside the pdb as the last record: length = ByteWriter.writeUshort(buffer, 0, (ushort)files.Count); fsOut.Write(buffer, 0, length); fsOut.Close(); }
// pack single image file into a .pdb file: public void PackImageIntoPdb(string name, string srcFilePath, string pdbFilePath, int format) { FileStream fsOut = new FileStream(pdbFilePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); // images: ArrayList files = new ArrayList(); // of FileInfo of .bmp or .jpg files ArrayList fileLengths = new ArrayList(); // of int, sizes of .bmp or .jpg files involved ArrayList cntFormats = new ArrayList(); // of int, just one counter at the end of pdb int maxFileLength = makeSingleImageArray(files, fileLengths, srcFilePath); cntFormats.Add(2); // just one ushort format indicator at the end of pdb int recCount = fileLengths.Count + cntFormats.Count; // make and write header: PDBHeader header = new PDBHeader(name, recCount); header.writeHeader(fsOut); // now write record locators, 8 bytes per each record, containing offsets of actual records: header.writeLocators(fsOut, fileLengths, recCount, true, false); // start writing header.writeLocators(fsOut, cntFormats, 0, false, true); // continue writing, finish with alignment // write actual records as length-specified strings (image name), followed by raw bmp data: byte[] buffer = new Byte[Math.Max(maxFileLength, 2 + 4 + 256)]; // 2 bytes for length, up to 4 for padding, 256 for image name int length = 0; for(int i=0; i < files.Count ;i++) { FileInfo fi = (FileInfo)files[i]; string imageName = fi.Name; length = ByteWriter.writeString (buffer, 0, imageName); fsOut.Write(buffer, 0, length); FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); length = fs.Read(buffer, 0, (int)fi.Length); fs.Close(); fsOut.Write(buffer, 0, length); } // write the number of image files inside the pdb as the last record: length = ByteWriter.writeUshort (buffer, 0, (ushort)format); fsOut.Write(buffer, 0, length); fsOut.Close(); }