Example #1
0
        public virtual void FileSpecCheckTest02()
        {
            String          outPdf       = destinationFolder + "pdfA3b_fileSpecCheckTest02.pdf";
            String          cmpPdf       = cmpFolder + "cmp_pdfA3b_fileSpecCheckTest02.pdf";
            PdfWriter       writer       = new PdfWriter(outPdf);
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, outputIntent);
            PdfPage      page        = pdfDocument.AddNewPage();
            PdfFont      font        = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true);
            PdfCanvas    canvas      = new PdfCanvas(page);

            canvas.SaveState().BeginText().MoveText(36, 700).SetFontAndSize(font, 36).ShowText("Hello World!").EndText
                ().RestoreState();
            MemoryStream           txt  = new MemoryStream();
            FormattingStreamWriter @out = new FormattingStreamWriter(txt);

            @out.Write("<foo><foo2>Hello world</foo2></foo>");
            @out.Dispose();
            pdfDocument.AddAssociatedFile("foo file", PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, txt.ToArray(), "foo file"
                                                                                         , "foo.xml", null, PdfName.Unspecified));
            pdfDocument.Close();
            CompareResult(outPdf, cmpPdf);
        }
Example #2
0
        /// <summary>
        /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
        /// the given stream, specification version and the format.
        /// </summary>
        /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
        /// <param name="element">The Open API element.</param>
        /// <param name="stream">The given stream.</param>
        /// <param name="specVersion">The Open API specification version.</param>
        /// <param name="format">The output format (JSON or YAML).</param>
        /// <param name="settings">Provide configuration settings for controlling writing output</param>
        public static void Serialize <T>(
            this T element,
            Stream stream,
            OpenApiSpecVersion specVersion,
            OpenApiFormat format,
            OpenApiWriterSettings settings = null)
            where T : IOpenApiSerializable
        {
            if (stream == null)
            {
                throw Error.ArgumentNull(nameof(stream));
            }

            IOpenApiWriter writer;
            var            streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);

            switch (format)
            {
            case OpenApiFormat.Json:
                writer = new OpenApiJsonWriter(streamWriter, settings);
                break;

            case OpenApiFormat.Yaml:
                writer = new OpenApiYamlWriter(streamWriter, settings);
                break;

            default:
                throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format));
            }

            element.Serialize(writer, specVersion);
        }
        public void Write(ArchiveListing listing, out ArchiveListingBlockInfo[] blocksInfo, out ArchiveListingEntryInfoV2[] entriesInfoV2)
        {
            using (MemoryStream ms = new MemoryStream(32768))
            {
                int blockNumber = 0, unpackedBlockOffset = 0;
                entriesInfoV2 = new ArchiveListingEntryInfoV2[listing.Count];
                List <ArchiveListingBlockInfo> blocks = new List <ArchiveListingBlockInfo>(128);
                using (FormattingStreamWriter sw = new FormattingStreamWriter(ms, Encoding.ASCII, 4096, true, CultureInfo.InvariantCulture))
                {
                    sw.AutoFlush = true;
                    for (int i = 0; i < listing.Count; i++)
                    {
                        ArchiveEntry entry = listing[i];

                        ArchiveListingEntryInfoV2 info = new ArchiveListingEntryInfoV2 {
                            BlockNumber = (short)(ms.Position / 8192)
                        };
                        info.Flag = (info.BlockNumber % 2 != 0);

                        entriesInfoV2[i] = info;

                        if (blockNumber != info.BlockNumber)
                        {
                            int blockSize = (int)(ms.Position - unpackedBlockOffset);
                            ms.Position = unpackedBlockOffset;
                            ArchiveListingBlockInfo block = new ArchiveListingBlockInfo {
                                Offset = (int)_output.Position, UncompressedSize = blockSize
                            };
                            block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize);
                            blocks.Add(block);

                            blockNumber++;
                            unpackedBlockOffset = (int)ms.Position;
                            sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name);
                        }
                        else if (i == listing.Count - 1)
                        {
                            info.Offset = (short)(ms.Position - unpackedBlockOffset);
                            sw.Write("{0:x}:{1:x}:{2:x}:{3}\0end\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name);
                            int blockSize = (int)(ms.Position - unpackedBlockOffset);
                            ms.Position = unpackedBlockOffset;
                            ArchiveListingBlockInfo block = new ArchiveListingBlockInfo {
                                Offset = (int)_output.Position, UncompressedSize = blockSize
                            };
                            block.CompressedSize = ZLibHelper.Compress(ms, _output, block.UncompressedSize);
                            blocks.Add(block);
                        }
                        else
                        {
                            info.Offset = (short)(ms.Position - unpackedBlockOffset);
                            sw.Write("{0:x}:{1:x}:{2:x}:{3}\0", entry.Sector, entry.UncompressedSize, entry.Size, entry.Name);
                        }
                    }
                }
                blocksInfo = blocks.ToArray();
            }
        }
        public virtual void Dump(FormattingStreamWriter output)
        {
            int i;

            for (i = 258; i < numStrings_; ++i)
            {
                output.WriteLine(" strNxt_[" + i + "] = " + strNxt_[i] + " strChr_ " + JavaUtil.IntegerToHexString(strChr_
                                                                                                                   [i] & 0xFF) + " strLen_ " + JavaUtil.IntegerToHexString(strLen_[i]));
            }
        }
Example #5
0
File: Toml.cs Project: zanedp/Nett
 private static string WriteStringInternal(TomlTable table)
 {
     using (var ms = new MemoryStream(1024))
     {
         var sw     = new FormattingStreamWriter(ms, CultureInfo.InvariantCulture);
         var writer = new TomlTableWriter(sw, table.Root.Settings);
         writer.WriteToml(table);
         ms.Position = 0;
         StreamReader sr = new StreamReader(ms);
         return(sr.ReadToEnd());
     }
 }
Example #6
0
 private static string WriteIntoStream(Action <FormattingStreamWriter> write)
 {
     using (var ms = new MemoryStream(1024))
     {
         var sw = new FormattingStreamWriter(ms, CultureInfo.InvariantCulture);
         write(sw);
         sw.Flush();
         ms.Position = 0;
         StreamReader sr = new StreamReader(ms);
         return(sr.ReadToEnd());
     }
 }
Example #7
0
File: Toml.cs Project: zanedp/Nett
        private static void WriteStreamInternal(TomlTable table, Stream outStream)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (outStream == null)
            {
                throw new ArgumentNullException(nameof(outStream));
            }

            var sw = new FormattingStreamWriter(outStream, CultureInfo.InvariantCulture);
            var tw = new TomlTableWriter(sw, table.Root.Settings);

            tw.WriteToml(table);
            outStream.Position = 0;
        }
Example #8
0
File: Toml.cs Project: zanedp/Nett
        private static void WriteFileInternal(TomlTable table, string filePath, TomlSettings settings)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            filePath.EnsureDirectoryExists();

            using (var fs = new FileStream(filePath, FileMode.Create))
                using (var sw = new FormattingStreamWriter(fs, CultureInfo.InvariantCulture))
                {
                    var writer = new TomlTableWriter(sw, settings);
                    writer.WriteToml(table);
                }
        }
Example #9
0
 /// <summary>Creates a new instance of Pfm2afm</summary>
 private Pfm2afm(RandomAccessFileOrArray input, Stream output)
 {
     this.input  = input;
     this.output = (FormattingStreamWriter)FileUtil.CreatePrintWriter(output, "ISO-8859-1");
 }
Example #10
0
 public TomlWriter(FormattingStreamWriter writer, TomlSettings settings)
 {
     this.writer   = writer;
     this.settings = settings;
 }
Example #11
0
 public DottedTableWriter(FormattingStreamWriter writer, TomlSettings settings)
     : base(writer, settings)
 {
 }
Example #12
0
 public TomlInlineTableWriter(FormattingStreamWriter writer, TomlSettings settings)
     : base(writer, settings)
 {
 }
Example #13
0
 public TomlTableWriter(FormattingStreamWriter writer, TomlSettings settings)
     : base(writer, settings)
 {
     Assert(writer != null);
     Assert(settings != null);
 }
Example #14
0
 public TomlInlineTableWriter(FormattingStreamWriter writer, TomlConfig config)
     : base(writer, config)
 {
 }