Пример #1
0
        public virtual void SeekTest()
        {
            String data = "/Name1 70";

            PdfTokenizer.TokenType[] expectedTypes = new PdfTokenizer.TokenType[] { PdfTokenizer.TokenType.Name, PdfTokenizer.TokenType
                                                                                    .Number, PdfTokenizer.TokenType.EndOfFile };
            RandomAccessSourceFactory factory = new RandomAccessSourceFactory();
            PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(data.GetBytes(iText.IO.Util.EncodingUtil.ISO_8859_1
                                                                                                               ))));

            tok.Seek(0);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[0], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("Name1", tok.GetStringValue());
            tok.Seek(7);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[1], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("70", tok.GetStringValue());
            tok.Seek(8);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[1], tok.GetTokenType());
            NUnit.Framework.Assert.AreEqual("0", tok.GetStringValue());
            tok.Seek(9);
            tok.NextValidToken();
            NUnit.Framework.Assert.AreEqual(expectedTypes[2], tok.GetTokenType());
        }
Пример #2
0
 /// <summary>Check whether line starts with object declaration.</summary>
 /// <param name="lineTokenizer">tokenizer, built by single line.</param>
 /// <returns>object number and generation if check is successful, otherwise - null.</returns>
 public static int[] CheckObjectStart(PdfTokenizer lineTokenizer)
 {
     try {
         lineTokenizer.Seek(0);
         if (!lineTokenizer.NextToken() || lineTokenizer.GetTokenType() != PdfTokenizer.TokenType.Number)
         {
             return(null);
         }
         int num = lineTokenizer.GetIntValue();
         if (!lineTokenizer.NextToken() || lineTokenizer.GetTokenType() != PdfTokenizer.TokenType.Number)
         {
             return(null);
         }
         int gen = lineTokenizer.GetIntValue();
         if (!lineTokenizer.NextToken())
         {
             return(null);
         }
         if (!JavaUtil.ArraysEquals(Obj, lineTokenizer.GetByteContent()))
         {
             return(null);
         }
         return(new int[] { num, gen });
     }
     catch (Exception) {
     }
     // empty on purpose
     return(null);
 }