|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectopencard.opt.iso.fs.CardFile
public class CardFile
Represents a file or directory on the smartcard. A card file object is a combination of an absolute path to the file represented, and the file information that was obtained from the smartcard on creation of the object. It provides methods to navigate through the smartcard's file system, and to obtain meta information about the files and directories therein. To access file contents, classes like CardFileInputStream, CardFileOutputStream, CardRandomByteAccess, or CardRandomRecordAccess can be instantiated.
To instantiate class CardFile, a FileAccessCardService
has to be provided. This service is used in the constructor to check
whether the file that shall be represented actually exists, and to query
meta information about the file. A card file object representing a
directory or, in smartcard terminology, a dedicated file (DF), can be
used to access other directories or files in the respective subtree of
the smartcard's file system. The path names for these files must be
relative to the represented directory. An absolute path will be created
for newly created card file objects, which will use the same file service
that was used by the parent object.
Smartcards use 16 bit numbers to identify files and directories. Human
friendly names are supported by a software layer, which has no platform
dependencies. Card file names are represented by instances of class
CardFilePath, for which different path components are defined.
Class CardFile supports only path components that can be
interpreted by the underlying file service. These components are
file IDs, and optionally short file IDs and application identifiers.
The string representation of a file ID is a colon, followed by a four
digit hex number specifying the afforementioned 16 bit number. These
file IDs can be concatenated to a path, for example ":BEEB:CAFE".
Support for symbolic path names, like "/mama/papa/dog" may be
added by derived classes.
CardFilePath objects can be created directly from strings.
To reduce memory requirements and to speed up operation, applications
should create each path only once and use it directly later on, instead
of using strings and creating paths any time they are needed. To
enforce this behavior, only constructors of class CardFile
accept strings instead of paths. The path created can be obtained
using CardFile.getPath.
Since the path to the file is part of this class, it corresponds to class
java.io.File. Many of the methods found there are implemented
here, too. Some others are implemented with slightly different signatures,
but comparable functionality. However, there are significant differences
between a standard disk file system and the file system on a smartcard,
which are reflected in CardFile.
Class java.io.file represents only a filename, on which
symbolic operations can be performed, and which can be used to access an
actual file on the underlying file system. Class CardFile
represents actual files. It cannot be instantiated for files that do not
exist. An operation like exists() does therefore not make sense.
Other examples for methods that are not provided are renameTo
and both list methods, since smartcards do not support file
renaming, and typically do not support browsing directories.
Traditional disk based file systems maintain file attributes like the
time of the last modification, or access conditions. Smartcards do not
support creation or modification times, and the access conditions are
too complex to be mapped on methods as simple as canRead and
canWrite. Support for platform dependent file separators, which
is provided via attributes like pathSeparator in class
java.io.File, do not make sense for smartcards either. The
string representation of card file paths is interpreted by a platform
neutral software layer.
Class CardFile provides methods like create and
delete, which are not supported by the interface
FileAccessCardService. These methods are available only if
an implementation of FileSystemCardService has been used to
create the card file object. This is checked with the Java operator
instanceof, so the methods may even be available if an
application is not aware of it.
The assumption for this implementation is that an application that needs
creational methods will request a FileSystemCardService, while
an application that does not need them will not invoke those methods.
There is a small chance for programming errors if the file service used
for testing implements both interfaces and there is no service that
implements only FileAccessCardService.
CardFileInputStream
,
CardFileOutputStream
,
CardRandomByteAccess
,
CardRandomRecordAccess
,
CardFilePath
,
getPath()
,
FileAccessCardService
,
FileSystemCardService
,
File
,
File.exists()
,
File.renameTo(java.io.File)
,
File.list()
,
File.list(java.io.FilenameFilter)
,
File.canRead()
,
File.canWrite()
,
File.pathSeparator
Field Summary | |
---|---|
protected CardFileInfo |
file_info
The information about the file represented. |
Constructor Summary | |
---|---|
|
CardFile(CardFile base,
CardFilePath relpath)
Creates a card file for the specified relative path. |
|
CardFile(CardFile base,
CardFilePathComponent comp)
Creates a card file for the specified path component. |
protected |
CardFile(CardFilePath path,
FileAccessCardService service)
Creates a card file, for internal purposes. |
|
CardFile(CardFile base,
java.lang.String relpath)
Creates a card file for the relative path specified as string. |
|
CardFile(FileAccessCardService service)
Creates a root card file. |
|
CardFile(FileAccessCardService service,
CardFilePath abspath)
Creates a card file object for the specified absolute path. |
|
CardFile(FileAccessCardService service,
java.lang.String abspath)
Creates a card file object for an absolute path given as string. |
Method Summary | |
---|---|
void |
create(byte[] data)
Creates a file on the smartcard. |
void |
delete(CardFilePath relpath)
Deletes a file on the smartcard. |
boolean |
exists(CardFilePath relpath)
Tests whether a given file exists. |
CardFilePath |
getAbsolutePath()
Returns the absolute path of the file represented. |
CardFilePath |
getCanonicalPath()
Returns the canonical path of the file represented. |
protected FileAccessCardService |
getFileAccessService()
Returns the underlying file access card service. |
short |
getFileID()
Returns the identifier of the file represented. |
CardFileInfo |
getFileInfo()
Returns information about the file represented. |
protected FileSystemCardService |
getFileSystemService()
Returns the underlying file system card service. |
byte[] |
getHeader()
Returns the header of the file represented. |
int |
getLength()
Returns the length of the file represented. |
java.lang.String |
getName()
Returns the name of the file represented. |
CardFile |
getParent()
Return the parent CardFile. |
CardFilePath |
getPath()
Returns the path of the file represented. |
int |
getRecordSize()
Returns the record size of the file represented. |
int |
hashCode()
Returns a hash code for this object. |
boolean |
isCyclic()
Checks whether the file represented is a cyclic file. |
boolean |
isDF()
Checks whether this card file represents a dedicated file (directory). |
boolean |
isDirectory()
Checks whether the file represented is a directory. |
boolean |
isEF()
Checks whether this card file represents an elementary file. |
boolean |
isFile()
Checks whether the file represented is a non-directory file. |
boolean |
isTransparent()
Checks whether the file represented is a transparent file. |
boolean |
isVariable()
Checks whether the file represented is a variable record file. |
protected CardFilePath |
resolvePath(CardFilePath path)
Provides a hook for resolving symbolic path components. |
java.lang.String |
toString()
Returns a human-readable string representation of this card file object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CardFileInfo file_info
Constructor Detail |
---|
public CardFile(FileAccessCardService service) throws java.io.FileNotFoundException, OpenCardException
service
- the file service to use for accessing the smartcard
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongpublic CardFile(FileAccessCardService service, CardFilePath abspath) throws java.io.FileNotFoundException, OpenCardException
service
- the underlying file serviceabspath
- the absolute path to the file to represent
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongpublic CardFile(FileAccessCardService service, java.lang.String abspath) throws java.io.FileNotFoundException, OpenCardException
service
- the underlying file serviceabspath
- a string holding the absolute path
to the file to represent
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongpublic CardFile(CardFile base, CardFilePath relpath) throws java.io.FileNotFoundException, OpenCardException
base
- the file representing the base directoryrelpath
- the path to the file, relative to the base directory
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongpublic CardFile(CardFile base, java.lang.String relpath) throws java.io.FileNotFoundException, OpenCardException
base
- the file representing the base directoryrelpath
- the path to the file, relative to the base directory
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongCardFile(opencard.opt.iso.fs.CardFile, opencard.opt.iso.fs.CardFilePath)
public CardFile(CardFile base, CardFilePathComponent comp) throws java.io.FileNotFoundException, OpenCardException
base
- the file representing the base directorycomp
- the file in the base directory that will be represented
java.io.FileNotFoundException
- if the file to represent could not be found
OpenCardException
- if anything else went wrongprotected CardFile(CardFilePath path, FileAccessCardService service) throws java.io.FileNotFoundException, CardServiceException, CardTerminalException
path
- the absolute path to the file representedservice
- the file service to use for accessing the smartcard
java.io.FileNotFoundException
- If the file does not exist on the smartcard.
CardServiceException
- If the underlying file service encountered an error.
CardTerminalException
- If communication to the smartcard failed.Method Detail |
---|
public final CardFilePath getCanonicalPath()
getAbsolutePath()
public CardFilePath getAbsolutePath()
getCanonicalPath()
public final CardFilePath getPath()
getCanonicalPath()
,
FileAccessCardService
,
FileSystemCardService
public java.lang.String getName()
public final short getFileID()
getFileID
in interface CardFileInfo
CardFileInfo.getFileID()
public final boolean isDirectory()
isDirectory
in interface CardFileInfo
CardFileInfo.isDirectory()
public final boolean isFile()
isDirectory()
public final boolean isDF()
isDirectory()
public final boolean isEF()
isFile()
public final boolean isTransparent()
isTransparent
in interface CardFileInfo
CardFileInfo.isTransparent()
public final boolean isCyclic()
isCyclic
in interface CardFileInfo
CardFileInfo.isCyclic()
public final boolean isVariable()
isVariable
in interface CardFileInfo
CardFileInfo.isVariable()
public final int getLength()
getLength
in interface CardFileInfo
CardFileInfo.getLength()
public final int getRecordSize()
getRecordSize
in interface CardFileInfo
CardFileInfo.getRecordSize()
public final byte[] getHeader()
getHeader
in interface CardFileInfo
getFileInfo()
,
CardFileInfo
,
CardFileInfo.getHeader()
protected final FileAccessCardService getFileAccessService()
protected final FileSystemCardService getFileSystemService()
protected CardFilePath resolvePath(CardFilePath path)
path
- a path that may contain symbolic components
getCanonicalPath()
public CardFile getParent()
public boolean exists(CardFilePath relpath)
relpath
- path to the file to check for existance
public final CardFileInfo getFileInfo()
FileAccessCardService.getFileInfo(opencard.opt.iso.fs.CardFilePath)
public final void create(byte[] data) throws CardServiceInabilityException, OpenCardException
data
- a card-specific parameter block specifying the file to create
CardServiceInabilityException
- if the underlying card service does not support creating files
OpenCardException
- if something else went wrongFileSystemCardService
,
FileSystemCardService.create(opencard.opt.iso.fs.CardFilePath, byte[])
public void delete(CardFilePath relpath) throws CardServiceInabilityException, OpenCardException
relpath
- the path to the file to delete,
relative to this card file
CardServiceInabilityException
- if the underlying card service does not support deleting files
OpenCardException
- if something else went wrongFileSystemCardService
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |