JX Application Framework
Loading...
Searching...
No Matches
Functions
jFStreamUtil.h File Reference
#include "jTypes.h"
#include <fstream>
Include dependency graph for jFStreamUtil.h:
This graph shows which files directly or indirectly include this file:

Functions

void JReadFile (const JString &fileName, JString *str)
 
void JReadFile (std::ifstream &input, JString *str)
 
void JReadFile (std::fstream &input, JString *str)
 
JSize JGetFStreamLength (std::ifstream &theStream)
 
JSize JGetFStreamLength (std::fstream &theStream)
 
std::fstream * JSetFStreamLength (const char *fileName, std::fstream &originalStream, const JSize newLength, const JFStreamOpenMode io_mode)
 
std::fstream * JSetFStreamLength (const JString &fileName, std::fstream &originalStream, const JSize newLength, const JFStreamOpenMode io_mode)
 
bool JConvertToStream (const int input, std::ifstream *input2, JString *tempFullName, const bool closeInput=true)
 

Function Documentation

◆ JConvertToStream()

bool JConvertToStream ( const int  input,
std::ifstream *  input2,
JString tempFullName,
const bool  closeInput 
)

Convert the data from the given file descriptor into an std::ifstream. The location of the file is returned in tempFullName.

This would be unnecessary if libstdc++ provided a stream wrapper for arbitrary file descriptors.

◆ JGetFStreamLength() [1/2]

JSize JGetFStreamLength ( std::fstream &  theStream)

◆ JGetFStreamLength() [2/2]

JSize JGetFStreamLength ( std::ifstream &  theStream)

Returns the length of the file associated with theStream.

◆ JReadFile() [1/3]

void JReadFile ( const JString fileName,
JString str 
)

Read characters from the std::fstream until the end of the file is reached. These functions takes a JString* because the contents of the file could be very large, and returning a JString requires twice as much memory because of the copy constructor.

These are equivalent to JReadAll() in jStreamUtil.h, except that they are optimized to work with file streams.

◆ JReadFile() [2/3]

void JReadFile ( std::fstream &  input,
JString str 
)

◆ JReadFile() [3/3]

void JReadFile ( std::ifstream &  input,
JString str 
)

◆ JSetFStreamLength() [1/2]

std::fstream * JSetFStreamLength ( const char *  fileName,
std::fstream &  originalStream,
const JSize  newLength,
const JFStreamOpenMode  io_mode 
)

◆ JSetFStreamLength() [2/2]

std::fstream * JSetFStreamLength ( const JString fileName,
std::fstream &  originalStream,
const JSize  newLength,
const JFStreamOpenMode  io_mode 
)

Sets the length of the file associated with originalStream.

The only efficient way is to use ftruncate(), which requires a file descriptor. Since we can't get this from the stream, we require the file name. Once we operate on the descriptor, the stream will be hopelessly confused, so we have to close it first. This is why we return a jnew one afterwards.

The caller is responsible for deleting originalStream.