ToBytesUTF8() public static method

Converts to bytes using UTF-8
public static ToBytesUTF8 ( String x ) : byte[]
x String
return byte[]
Esempio n. 1
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream memoryStream = new MemoryStream();

            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(key));
            memoryStream.WriteByte(0);
            memoryStream.WriteByte((byte)(compressed ? 1 : 0));
            memoryStream.WriteByte(0);
            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(langTag));
            memoryStream.WriteByte(0);
            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytesUTF8(translatedTag));
            memoryStream.WriteByte(0);
            byte[] array = ChunkHelper.ToBytesUTF8(val);
            if (compressed)
            {
                array = ChunkHelper.compressBytes(array, compress: true);
            }
            ChunkHelper.WriteBytesToStream(memoryStream, array);
            byte[]   array2   = memoryStream.ToArray();
            ChunkRaw chunkRaw = createEmptyChunk(array2.Length, alloc: false);

            chunkRaw.Data = array2;
            return(chunkRaw);
        }
Esempio n. 2
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream ba = new MemoryStream();

            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(key));
            ba.WriteByte(0); // separator
            ba.WriteByte(compressed ? (byte)1 : (byte)0);
            ba.WriteByte(0); // compression method (always 0)
            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(langTag));
            ba.WriteByte(0); // separator
            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytesUTF8(translatedTag));
            ba.WriteByte(0); // separator
            byte[] textbytes = ChunkHelper.ToBytesUTF8(val);
            if (compressed)
            {
                textbytes = ChunkHelper.compressBytes(textbytes, true);
            }
            ChunkHelper.WriteBytesToStream(ba, textbytes);
            byte[]   b     = ba.ToArray();
            ChunkRaw chunk = createEmptyChunk(b.Length, false);

            chunk.Data = b;
            return(chunk);
        }