UncompressedFileType Class Reference
Inheritance diagram for UncompressedFileType:
[legend]
Collaboration diagram for UncompressedFileType:
[legend]

## Public Member Functions

| UncompressedFileType (const char *filename, const char *mode)
bool | operator== (void *rhs)
bool | operator!= (void *rhs)
int | close ()
void | rewind ()
int | eof ()
virtual bool | isOpen ()
unsigned int | write (const void *buffer, unsigned int size)
int | read (void *buffer, unsigned int size)
virtual int64_t | tell ()
virtual bool | seek (int64_t offset, int origin)
Public Member Functions inherited from FileType
virtual bool | operator== (void *rhs)=0
virtual bool | operator!= (void *rhs)=0
virtual int | close ()=0
virtual void | rewind ()=0
virtual int | eof ()=0
virtual bool | isOpen ()=0
virtual unsigned int | write (const void *buffer, unsigned int size)=0
virtual int | read (void *buffer, unsigned int size)=0
virtual int64_t | tell ()=0
virtual bool | seek (int64_t offset, int origin)=0
void | setBuffered (bool buffered)
virtual bool | attemptRecoverySync (bool(*checkSignature)(void *data), int length)

## Protected Attributes

FILE * | filePtr
knetFile * | kfilePtr
bool | keof
Protected Attributes inherited from FileType
bool | myUsingBuffer

## Detailed Description

Definition at line 26 of file UncompressedFileType.h.

## Constructor & Destructor Documentation

## UncompressedFileType() [1/2]

UncompressedFileType::UncompressedFileType | ( |  | ) |

inline

Definition at line 29 of file UncompressedFileType.h.

{
filePtr = NULL;
kfilePtr = NULL;
keof = false;
}

## ~UncompressedFileType()

virtual UncompressedFileType::~UncompressedFileType | ( |  | ) |

inline virtual

Definition at line 36 of file UncompressedFileType.h.

{
if((filePtr != NULL) || (kfilePtr != NULL))
{
close();
}
}

## UncompressedFileType() [2/2]

UncompressedFileType::UncompressedFileType | ( | const char * | filename,
|  | const char * | mode
| ) |  |

Definition at line 21 of file UncompressedFileType.cpp.

: filePtr(NULL),
kfilePtr(NULL),
keof(false)
{
// Check if opening for read.
if((mode[0] == 'r') || (mode[0] == 'R'))
{
if(strcmp(filename, "-") == 0)
{
// read from stdin
filePtr = stdin;
}
else if((strstr(filename, "ftp://") == filename) ||
(strstr(filename, "http://") == filename))
{
// Reading http/ftp, so open the file using knetfile.
kfilePtr = knet_open(filename, mode);
}
else
{
// Open the file.
filePtr = fopen(filename, mode);
}
}
else
{
// Not for read.
// If the file is for write and is '-', then write to stdout.
if(((mode[0] == 'w') || (mode[0] == 'W')) &&
(strcmp(filename, "-") == 0))
{
// Write to stdout.
filePtr = stdout;
}
else
{
// Open the file.
filePtr = fopen(filename, mode);
}
}
};

## Member Function Documentation

## close()

int UncompressedFileType::close | ( |  | ) |

inline virtual

Implements FileType.

Definition at line 68 of file UncompressedFileType.h.

{
if(filePtr != NULL)
{
if((filePtr != stdout) && (filePtr != stdin))
{
int result = fclose(filePtr);
filePtr = NULL;
return result;
}
filePtr = NULL;
}
else if(kfilePtr != NULL)
{
int result = knet_close(kfilePtr);
kfilePtr = NULL;
return result;
}
return 0;
}

## eof()

int UncompressedFileType::eof | ( |  | ) |

inline virtual

Implements FileType.

Definition at line 105 of file UncompressedFileType.h.

{
// check the file for eof.
if(kfilePtr != NULL)
{
return(keof);
}
else
{
return feof(filePtr);
}
}

## isOpen()

virtual bool UncompressedFileType::isOpen | ( |  | ) |

inline virtual

Implements FileType.

Definition at line 119 of file UncompressedFileType.h.

{
if((filePtr != NULL) || (kfilePtr != NULL))
{
// filePtr is not null, so the file is open.
return(true);
}
return(false);
}

## operator!=()

bool UncompressedFileType::operator!= | ( | void * | rhs | ) |

inline virtual

Implements FileType.

Definition at line 56 of file UncompressedFileType.h.

{
// No two file pointers are the same, so if rhs is not NULL, then
// the two pointers are different (true).
if (rhs != NULL)
return true;
// rhs is NULL. They are the different if either filePtr or kfilePtr
// are not NULL.
return((filePtr != rhs) || (kfilePtr != rhs));
}

## operator==()

bool UncompressedFileType::operator== | ( | void * | rhs | ) |

inline virtual

Implements FileType.

Definition at line 46 of file UncompressedFileType.h.

{
// No two file pointers are the same, so if rhs is not NULL, then
// the two pointers are different (false).
if (rhs != NULL)
return false;
// rhs is NULL. They are the same if both filePtr & kfilePtr are NULL.
return((filePtr == rhs) && (kfilePtr == rhs));
}

## read()

int UncompressedFileType::read | ( | void * | buffer,
|  | unsigned int | size
| ) |  |

inline virtual

Implements FileType.

Definition at line 139 of file UncompressedFileType.h.

{
if(kfilePtr != NULL)
{
int bytesRead = knet_read(kfilePtr, buffer, size);
if((bytesRead == 0) && (size != 0))
{
keof = true;
}
else if((bytesRead != (int)size) && (bytesRead >= 0))
{
// Less then the requested size was read and an error
// was not returned (bgzf_read returns -1 on error).
keof = true;
}
else
{
keof = false;
}
return(bytesRead);
}
return fread(buffer, 1, size, filePtr);
}

## rewind()

void UncompressedFileType::rewind | ( |  | ) |

inline virtual

Implements FileType.

Definition at line 91 of file UncompressedFileType.h.

{
// Just call rewind to move to the beginning of the file.
if(filePtr != NULL)
{
::rewind(filePtr);
}
else if (kfilePtr != NULL)
{
knet_seek(kfilePtr, 0, SEEK_SET);
}
}

## seek()

virtual bool UncompressedFileType::seek | ( | int64_t | offset,
|  | int | origin
| ) |  |

inline virtual

Implements FileType.

Definition at line 183 of file UncompressedFileType.h.

{
int returnVal = 0;
if(kfilePtr != NULL)
{
returnVal = knet_seek(kfilePtr, offset, origin);
keof = false;
}
else
{
returnVal = fseek(filePtr, offset, origin);
}
// Check for success - 0 return value.
if (returnVal == 0)
{
return true;
}
// Successful.
return false;
}

## tell()

virtual int64_t UncompressedFileType::tell | ( |  | ) |

inline virtual

Implements FileType.

Definition at line 166 of file UncompressedFileType.h.

{
if(kfilePtr != NULL)
{
return knet_tell(kfilePtr);
}
return ftell(filePtr);
}

## write()

unsigned int UncompressedFileType::write | ( | const void * | buffer,
|  | unsigned int | size
| ) |  |

inline virtual

Implements FileType.

Definition at line 130 of file UncompressedFileType.h.

{
// knetfile is never used for writing.
return fwrite(buffer, 1, size, filePtr);
}

## Member Data Documentation

## filePtr

FILE* UncompressedFileType::filePtr

protected

Definition at line 207 of file UncompressedFileType.h.

## keof

bool UncompressedFileType::keof

protected

Definition at line 209 of file UncompressedFileType.h.

## kfilePtr

knetFile* UncompressedFileType::kfilePtr

protected

Definition at line 208 of file UncompressedFileType.h.

The documentation for this class was generated from the following files:

- general/UncompressedFileType.h
- general/UncompressedFileType.cpp