internal virtual void ReadSegment(Jbig2SegmentReader.Jbig2Segment s)
        {
            int ptr = (int)ra.GetPosition();

            if (s.dataLength == unchecked ((long)(0xffffffffl)))
            {
                // TODO figure this bit out, 7.2.7
                return;
            }
            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;
            if (s.type == PAGE_INFORMATION)
            {
                int last = (int)ra.GetPosition();
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                Jbig2SegmentReader.Jbig2Page p = pages.Get(s.page);
                if (p == null)
                {
                    throw new iText.IO.IOException("Referring to widht or height of a page we haven't seen yet: {0}").SetMessageParams
                              (s.page);
                }
                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
예제 #2
0
        void ReadSegment(JBIG2Segment s)
        {
            int ptr = ra.FilePointer;

            if (s.dataLength == 0xffffffffL)
            {
                // TODO figure this bit out, 7.2.7
                return;
            }

            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;

            if (s.type == PAGE_INFORMATION)
            {
                int last = ra.FilePointer;
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                JBIG2Page p = pages[s.page];
                if (p == null)
                {
                    throw new InvalidOperationException(MessageLocalization.GetComposedMessage("referring.to.widht.height.of.page.we.havent.seen.yet.1", s.page));
                }

                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
        void ReadSegment(JBIG2Segment s)
        {
            int ptr = ra.FilePointer;

            if (s.dataLength == 0xffffffffL)
            {
                // TODO figure this bit out, 7.2.7
                return;
            }

            byte[] data = new byte[(int)s.dataLength];
            ra.Read(data);
            s.data = data;

            if (s.type == PAGE_INFORMATION)
            {
                int last = ra.FilePointer;
                ra.Seek(ptr);
                int page_bitmap_width  = ra.ReadInt();
                int page_bitmap_height = ra.ReadInt();
                ra.Seek(last);
                JBIG2Page p = (JBIG2Page)pages[s.page];
                if (p == null)
                {
                    throw new InvalidOperationException("referring to widht/height of page we havent seen yet? " + s.page);
                }

                p.pageBitmapWidth  = page_bitmap_width;
                p.pageBitmapHeight = page_bitmap_height;
            }
        }
        virtual public void TestSeek()
        {
            RandomAccessFileOrArray rafoa = new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(data));

            rafoa.Seek(72);
            for (int i = 72; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], (byte)rafoa.Read());
            }
        }
예제 #5
0
 /// <summary>Construct an icc profile from the passed random-access file or array.</summary>
 /// <param name="file">random-access file or array containing the profile</param>
 /// <returns>IccProfile constructed from the data</returns>
 /// <exception cref="iText.IO.IOException">if the source does not contain a valid icc profile</exception>
 public static iText.IO.Colors.IccProfile GetInstance(RandomAccessFileOrArray file)
 {
     try {
         byte[] head   = new byte[128];
         int    remain = head.Length;
         int    ptr    = 0;
         while (remain > 0)
         {
             int n = file.Read(head, ptr, remain);
             if (n < 0)
             {
                 throw new iText.IO.IOException(iText.IO.IOException.InvalidIccProfile);
             }
             remain -= n;
             ptr    += n;
         }
         if (head[36] != 0x61 || head[37] != 0x63 || head[38] != 0x73 || head[39] != 0x70)
         {
             throw new iText.IO.IOException(iText.IO.IOException.InvalidIccProfile);
         }
         remain = (head[0] & 0xff) << 24 | (head[1] & 0xff) << 16 | (head[2] & 0xff) << 8 | head[3] & 0xff;
         byte[] icc = new byte[remain];
         System.Array.Copy(head, 0, icc, 0, head.Length);
         remain -= head.Length;
         ptr     = head.Length;
         while (remain > 0)
         {
             int n = file.Read(icc, ptr, remain);
             if (n < 0)
             {
                 throw new iText.IO.IOException(iText.IO.IOException.InvalidIccProfile);
             }
             remain -= n;
             ptr    += n;
         }
         return(GetInstance(icc));
     }
     catch (Exception ex) {
         throw new iText.IO.IOException(iText.IO.IOException.InvalidIccProfile, ex);
     }
 }
예제 #6
0
 /// <exception cref="System.IO.IOException"/>
 public static void TransferBytes(RandomAccessFileOrArray input, Stream output)
 {
     byte[] buffer = new byte[TRANSFER_SIZE];
     for (; ;)
     {
         int len = input.Read(buffer, 0, TRANSFER_SIZE);
         if (len > 0)
         {
             output.Write(buffer, 0, len);
         }
         else
         {
             break;
         }
     }
 }
        virtual public void TestPushback_byteByByte()
        {
            Assert.AreEqual(data[0], (byte)rafoa.Read());
            Assert.AreEqual(data[1], (byte)rafoa.Read());
            byte pushBackVal = (byte)(data[1] + 42);

            rafoa.PushBack(pushBackVal);
            Assert.AreEqual(pushBackVal, (byte)rafoa.Read());
            Assert.AreEqual(data[2], (byte)rafoa.Read());
            Assert.AreEqual(data[3], (byte)rafoa.Read());
        }
예제 #8
0
        public static byte[] GetBytes(Uri uri)
        {
            WebRequest wr = WebRequest.Create(uri);

            wr.Credentials = CredentialCache.DefaultCredentials;
            var isp = wr.GetResponse().GetResponseStream();

            byte[] bytes = null;
            try
            {
                var a = new RandomAccessFileOrArray(isp);
                try
                {
                    using (var aa = new MemoryStream())
                    {
                        int b;
                        while ((b = a.Read()) != -1)
                        {
                            aa.WriteByte((byte)b);
                        }
                        bytes = aa.ToArray();
                    }
                }
                finally
                {
                    try
                    {
                        a.Close();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            finally
            {
                try
                {
                    isp.Close();
                }
                catch (Exception)
                {
                }
            }
            return(bytes);
        }
예제 #9
0
        private String ReadString()
        {
            StringBuilder buf = new StringBuilder();

            while (true)
            {
                int c = input.Read();
                if (c <= 0)
                {
                    break;
                }
                buf.Append((char)c);
            }
            return(buf.ToString());
        }
예제 #10
0
        public virtual byte[] GetFontStreamBytes()
        {
            if (fontParser.IsBuiltInFont())
            {
                return(null);
            }
            if (fontStreamBytes != null)
            {
                return(fontStreamBytes);
            }
            RandomAccessFileOrArray raf = null;

            try {
                raf = fontParser.GetPostscriptBinary();
                int fileLength = (int)raf.Length();
                fontStreamBytes   = new byte[fileLength - 18];
                fontStreamLengths = new int[3];
                int bytePtr = 0;
                for (int k = 0; k < 3; ++k)
                {
                    if (raf.Read() != 0x80)
                    {
                        ILog logger = LogManager.GetLogger(typeof(iText.IO.Font.Type1Font));
                        logger.Error(iText.IO.LogMessageConstant.START_MARKER_MISSING_IN_PFB_FILE);
                        return(null);
                    }
                    if (raf.Read() != PFB_TYPES[k])
                    {
                        ILog logger = LogManager.GetLogger(typeof(iText.IO.Font.Type1Font));
                        logger.Error("incorrect.segment.type.in.pfb.file");
                        return(null);
                    }
                    int size = raf.Read();
                    size += raf.Read() << 8;
                    size += raf.Read() << 16;
                    size += raf.Read() << 24;
                    fontStreamLengths[k] = size;
                    while (size != 0)
                    {
                        int got = raf.Read(fontStreamBytes, bytePtr, size);
                        if (got < 0)
                        {
                            ILog logger = LogManager.GetLogger(typeof(iText.IO.Font.Type1Font));
                            logger.Error("premature.end.in.pfb.file");
                            return(null);
                        }
                        bytePtr += got;
                        size    -= got;
                    }
                }
                return(fontStreamBytes);
            }
            catch (Exception) {
                ILog logger = LogManager.GetLogger(typeof(iText.IO.Font.Type1Font));
                logger.Error("type1.font.file.exception");
                return(null);
            }
            finally {
                if (raf != null)
                {
                    try {
                        raf.Close();
                    }
                    catch (Exception) {
                    }
                }
            }
        }