本文整理汇总了Java中com.lowagie.text.pdf.RandomAccessFileOrArray.seek方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFileOrArray.seek方法的具体用法?Java RandomAccessFileOrArray.seek怎么用?Java RandomAccessFileOrArray.seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.RandomAccessFileOrArray
的用法示例。
在下文中一共展示了RandomAccessFileOrArray.seek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例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;
}
示例3: 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;
}
示例4: process
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Reads the font data.
*
* @param ttfAfm
* the font as a <CODE>byte</CODE> array, possibly <CODE>null</CODE>
* @throws DocumentException
* the font is invalid
* @throws IOException
* the font file could not be read
*/
void process( ) throws DocumentException, IOException
{
positionTables = new HashMap<String, int[]>( );
metadataTables = new HashMap<String, byte[]>( );
try
{
rf = new RandomAccessFileOrArray( fileName );
if ( ttcIndex.length( ) > 0 )
{
int dirIdx = Integer.parseInt( ttcIndex );
if ( dirIdx < 0 )
throw new DocumentException( "The font index for "
+ fileName + " must be positive." );
String mainTag = readStandardString( 4 );
if ( !mainTag.equals( "ttcf" ) )
throw new DocumentException( fileName
+ " is not a valid TTC file." );
rf.skipBytes( 4 );
int dirCount = rf.readInt( );
if ( dirIdx >= dirCount )
throw new DocumentException( "The font index for "
+ fileName + " must be between 0 and "
+ ( dirCount - 1 ) + ". It was " + dirIdx + "." );
rf.skipBytes( dirIdx * 4 );
directoryOffset = rf.readInt( );
}
rf.seek( directoryOffset );
rf.readFully( directoryRawData );
int ttId = Util.getInt( directoryRawData, 0 );
if ( ttId != 0x00010000 && ttId != 0x4F54544F )
throw new DocumentException( fileName
+ " is not a valid TTF or OTF file." );
int num_tables = Util.getUnsignedShort( directoryRawData, 4 );
for ( int k = 0; k < num_tables; ++k )
{
byte[] rawData = new byte[16];
rf.readFully( rawData );
String tag = getStandardString( rawData, 0, 4 );
int table_location[] = new int[2];
table_location[0] = Util.getInt( rawData, 8 );
table_location[1] = Util.getInt( rawData, 12 );
positionTables.put( tag, table_location );
metadataTables.put( tag, rawData );
}
fontName = getBaseFont( );
fullName = getNames( 4 ); // full name
familyName = getNames( 1 ); // family name
notice = getNames( 0 );
version = getNames( 5 );
if ( !justNames )
{
fillTables( );
readGlyphWidths( );
readCMaps( );
readKerning( );
readBbox( );
GlyphWidths = null;
}
}
finally
{
if ( rf != null )
{
rf.close( );
if ( !embedded )
rf = null;
}
}
}
示例5: TIFFDirectory
import com.lowagie.text.pdf.RandomAccessFileOrArray; //导入方法依赖的package包/类
/**
* Constructs a TIFFDirectory from a SeekableStream.
* The directory parameter specifies which directory to read from
* the linked list present in the stream; directory 0 is normally
* read but it is possible to store multiple images in a single
* TIFF file by maintaing multiple directories.
*
* @param stream a SeekableStream to read from.
* @param directory the index of the directory to read.
*/
public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
throws IOException {
long global_save_offset = stream.getFilePointer();
long ifd_offset;
// Read the TIFF header
stream.seek(0L);
int endian = stream.readUnsignedShort();
if (!isValidEndianTag(endian)) {
throw new
IllegalArgumentException("Bad endianness tag (not 0x4949 or 0x4d4d).");
}
isBigEndian = (endian == 0x4d4d);
int magic = readUnsignedShort(stream);
if (magic != 42) {
throw new
IllegalArgumentException("Bad magic number, should be 42.");
}
// Get the initial ifd offset as an unsigned int (using a long)
ifd_offset = readUnsignedInt(stream);
for (int i = 0; i < directory; i++) {
if (ifd_offset == 0L) {
throw new
IllegalArgumentException("Directory number too large.");
}
stream.seek(ifd_offset);
int entries = readUnsignedShort(stream);
stream.skip(12*entries);
ifd_offset = readUnsignedInt(stream);
}
stream.seek(ifd_offset);
initialize(stream);
stream.seek(global_save_offset);
}