当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFileOrArray类代码示例

本文整理汇总了Java中com.lowagie.text.pdf.RandomAccessFileOrArray的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFileOrArray类的具体用法?Java RandomAccessFileOrArray怎么用?Java RandomAccessFileOrArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RandomAccessFileOrArray类属于com.lowagie.text.pdf包,在下文中一共展示了RandomAccessFileOrArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transparentTiffTest

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
@Test
public void transparentTiffTest() throws IOException {
    InputStream inputStream = TiffReadingTest.class.getClassLoader().getResourceAsStream("gradient.tiff");
    byte[] data;

    try(ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream()) {
        int bytesRead;
        byte[] buffer = new byte[8192];

        while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
            byteOutputStream.write(buffer, 0, bytesRead);
        }

        data = byteOutputStream.toByteArray();
    }

    RandomAccessFileOrArray ra = new RandomAccessFileOrArray(data);
    int pages = TiffImage.getNumberOfPages(ra);

    for (int i = 1; i <= pages; i++) {
        Assert.assertNotNull(TiffImage.getTiffImage(ra, i));
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:24,代码来源:TiffReadingTest.java

示例2: getNumDirectories

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * Returns the number of image directories (subimages) stored in a
 * given TIFF file, represented by a <code>SeekableStream</code>.
 */
public static int getNumDirectories(RandomAccessFileOrArray stream)
throws IOException{
    long pointer = stream.getFilePointer(); // Save stream pointer
    
    stream.seek(0L);
    int endian = stream.readUnsignedShort();
    if (!isValidEndianTag(endian)) {
        throw new
        IllegalArgumentException("Bad endianness tag (not 0x4949 or 0x4d4d).");
    }
    boolean isBigEndian = (endian == 0x4d4d);
    int magic = readUnsignedShort(stream, isBigEndian);
    if (magic != 42) {
        throw new
        IllegalArgumentException("Bad magic number, should be 42.");
    }
    
    stream.seek(4L);
    long offset = readUnsignedInt(stream, isBigEndian);
    
    int numDirectories = 0;
    while (offset != 0L) {
        ++numDirectories;
        
        // EOFException means IFD was probably not properly terminated.
        try {
            stream.seek(offset);
            int entries = readUnsignedShort(stream, isBigEndian);
            stream.skip(12*entries);
            offset = readUnsignedInt(stream, isBigEndian);
        } catch(EOFException eof) {
            numDirectories--;
            break;
        }
    }
    
    stream.seek(pointer); // Reset stream pointer
    return numDirectories;
}
 
开发者ID:MesquiteProject,项目名称:MesquiteArchive,代码行数:44,代码来源:TIFFDirectory.java

示例3: readFloat

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
private float readFloat(RandomAccessFileOrArray stream)
throws IOException {
    if (isBigEndian) {
        return stream.readFloat();
    } else {
        return stream.readFloatLE();
    }
}
 
开发者ID:MesquiteProject,项目名称:MesquiteArchive,代码行数:9,代码来源:TIFFDirectory.java

示例4: getContentBytesForPage

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * Gets the content stream of a page.
 * @param pageNum	the page number of page you want get the content stream from
 * @return	a byte array with the content stream of a page
 * @throws IOException
 */
private byte[] getContentBytesForPage(int pageNum) throws IOException {
    RandomAccessFileOrArray f = reader.getSafeFile();
    byte[] contentBytes = reader.getPageContent(pageNum, f);
    f.close();
    return contentBytes;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:13,代码来源:PdfTextExtractor.java

示例5: listContentStreamForPage

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * Writes information about a specific page from PdfReader to the specified output stream.
 * @since 2.1.5
 * @param reader    the PdfReader to read the page content from
 * @param pageNum   the page number to read
 * @param out       the output stream to send the content to
 * @throws IOException
 */
static public void listContentStreamForPage(PdfReader reader, int pageNum, PrintWriter out) throws IOException {
    out.println("==============Page " + pageNum + "====================");
    out.println("- - - - - Dictionary - - - - - -");
    PdfDictionary pageDictionary = reader.getPageN(pageNum);
    out.println(getDictionaryDetail(pageDictionary));
    out.println("- - - - - Content Stream - - - - - -");
    RandomAccessFileOrArray f = reader.getSafeFile();
    
    byte[] contentBytes = reader.getPageContent(pageNum, f);
    f.close();

    
    InputStream is = new ByteArrayInputStream(contentBytes);
    int ch;
    while ((ch = is.read()) != -1){
        out.print((char)ch);
    }

    out.println("- - - - - Text Extraction - - - - - -");
    PdfTextExtractor extractor = new PdfTextExtractor(reader);
    String extractedText = extractor.getTextFromPage(pageNum);
    if (extractedText.length() != 0)
        out.println(extractedText);
    else
        out.println("No text found on page " + pageNum);
    
    out.println();
    
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:38,代码来源:PdfContentReaderTool.java

示例6: getNumberOfPages

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/** Gets the number of pages the TIFF document has.
 * @param s the file source
 * @return the number of pages
 */    
public static int getNumberOfPages(RandomAccessFileOrArray s) {
    try {
        return TIFFDirectory.getNumDirectories(s);
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:13,代码来源:TiffImage.java

示例7: getGlobalSegment

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * Gets a byte array that can be used as a /JBIG2Globals,
 * or null if not applicable to the given jbig2.
 * @param	ra	an random access file or array
 * @return	a byte array
 */
public static byte[] getGlobalSegment(RandomAccessFileOrArray ra ) {
	try {
		JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
		sr.read();
		return sr.getGlobal(true);
	} catch (Exception e) {
        return null;
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:16,代码来源:JBIG2Image.java

示例8: getJbig2Image

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * returns an Image representing the given page.
 * @param ra	the file or array containing the image
 * @param page	the page number of the image
 * @return	an Image object
 */
public static Image getJbig2Image(RandomAccessFileOrArray ra, int page) {
	if (page < 1)
           throw new IllegalArgumentException("The page number must be >= 1.");
	
	try {
		JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
		sr.read();
		JBIG2SegmentReader.JBIG2Page p = sr.getPage(page);
		Image img = new ImgJBIG2(p.pageBitmapWidth, p.pageBitmapHeight, p.getData(true), sr.getGlobal(true));
		return img;
	} catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:21,代码来源:JBIG2Image.java

示例9: getNumberOfPages

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/***
 * Gets the number of pages in a JBIG2 image.
 * @param ra	a random acces file array containing a JBIG2 image
 * @return	the number of pages
 */
public static int getNumberOfPages(RandomAccessFileOrArray ra) {
	try {
		JBIG2SegmentReader sr = new JBIG2SegmentReader(ra);
		sr.read();
		return sr.numberOfPages();
	} catch (Exception e) {
        throw new ExceptionConverter(e);
    }
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:15,代码来源:JBIG2Image.java

示例10: TIFFDirectory

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
/**
 * Constructs a TIFFDirectory by reading a SeekableStream.
 * The ifd_offset parameter specifies the stream offset from which
 * to begin reading; this mechanism is sometimes used to store
 * private IFDs within a TIFF file that are not part of the normal
 * sequence of IFDs.
 *
 * @param stream a SeekableStream to read from.
 * @param ifd_offset the long byte offset of the directory.
 * @param directory the index of the directory to read beyond the
 *        one at the current stream offset; zero indicates the IFD
 *        at the current offset.
 */
public TIFFDirectory(RandomAccessFileOrArray stream, long ifd_offset, int directory)
throws IOException {
    
    long global_save_offset = stream.getFilePointer();
    stream.seek(0L);
    int endian = stream.readUnsignedShort();
    if (!isValidEndianTag(endian)) {
        throw new
        IllegalArgumentException("Bad endianness tag (not 0x4949 or 0x4d4d).");
    }
    isBigEndian = (endian == 0x4d4d);
    
    // Seek to the first IFD.
    stream.seek(ifd_offset);
    
    // Seek to desired IFD if necessary.
    int dirNum = 0;
    while(dirNum < directory) {
        // Get the number of fields in the current IFD.
        int numEntries = readUnsignedShort(stream);
        
        // Skip to the next IFD offset value field.
        stream.seek(ifd_offset + 12*numEntries);
        
        // Read the offset to the next IFD beyond this one.
        ifd_offset = readUnsignedInt(stream);
        
        // Seek to the next IFD.
        stream.seek(ifd_offset);
        
        // Increment the directory.
        dirNum++;
    }
    
    initialize(stream);
    stream.seek(global_save_offset);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:51,代码来源:TIFFDirectory.java

示例11: readShort

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
private short readShort(RandomAccessFileOrArray stream)
throws IOException {
    if (isBigEndian) {
        return stream.readShort();
    } else {
        return stream.readShortLE();
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:9,代码来源:TIFFDirectory.java

示例12: readUnsignedShort

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
private int readUnsignedShort(RandomAccessFileOrArray stream)
throws IOException {
    if (isBigEndian) {
        return stream.readUnsignedShort();
    } else {
        return stream.readUnsignedShortLE();
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:9,代码来源:TIFFDirectory.java

示例13: readInt

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
private int readInt(RandomAccessFileOrArray stream)
throws IOException {
    if (isBigEndian) {
        return stream.readInt();
    } else {
        return stream.readIntLE();
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:9,代码来源:TIFFDirectory.java

示例14: readUnsignedInt

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
private long readUnsignedInt(RandomAccessFileOrArray stream)
throws IOException {
    if (isBigEndian) {
        return stream.readUnsignedInt();
    } else {
        return stream.readUnsignedIntLE();
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:9,代码来源:TIFFDirectory.java

示例15: readLong

import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入依赖的package包/类
@SuppressWarnings("unused")
private long readLong(RandomAccessFileOrArray stream)
   throws IOException {
       if (isBigEndian) {
           return stream.readLong();
       } else {
           return stream.readLongLE();
       }
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:10,代码来源:TIFFDirectory.java


注:本文中的com.lowagie.text.pdf.RandomAccessFileOrArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。