/*
* Our base String stream classes. We implement these to
* be based on Glib::ustring
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Inkscape.org
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "uristream.h"
#include "sys.h"
#include <string>
#include <cstring>
namespace Inkscape
{
namespace IO
{
/*
* URI scheme types
*/
#define SCHEME_NONE 0
/*
* A temporary modification of Jon Cruz's portable fopen().
* Simplified a bit, since we will always use binary
*/
{
if (!utf8name)
{
return NULL;
}
{
return NULL;
}
#ifndef WIN32
if ( filename ) {
else
}
#else
{
if ( wideName ) {
else
} else {
}
}
#endif
return fp;
}
//#########################################################################
//# U R I I N P U T S T R E A M / R E A D E R
//#########################################################################
/**
*
*/
{
//get information from uri
switch (scheme) {
case SCHEME_FILE:
if (!inf) {
throw StreamException(err);
}
else{
}
break;
case SCHEME_DATA:
dataPos = 0;
break;
}
closed = false;
}
/**
*
*/
data(0),
dataPos(0),
dataLen(0),
closed(false)
{
if (!inf) {
throw StreamException(err);
}
}
/**
*
*/
{
close();
}
/**
* Returns the number of bytes that can be read (or skipped over) from
* this input stream without blocking by the next caller of a method for
* this input stream.
*/
{
return 0;
}
/**
* Closes this input stream and releases any system resources
* associated with the stream.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!inf)
return;
break;
case SCHEME_DATA:
//do nothing
break;
}//switch
closed = true;
}
/**
* Reads the next byte of data from the input stream. -1 if EOF
*/
{
if (!closed)
{
switch (scheme) {
case SCHEME_FILE:
{
retVal = -1;
}
else
{
}
break;
case SCHEME_DATA:
{
retVal = -1;
}
else
{
}
break;
}//switch
}
return retVal;
}
/**
*
*/
{
}
/**
*
*/
{
delete inputStream;
}
/**
*
*/
{
return inputStream->available();
}
/**
*
*/
{
inputStream->close();
}
/**
*
*/
{
return ch;
}
//#########################################################################
//# U R I O U T P U T S T R E A M / W R I T E R
//#########################################################################
/**
* Temporary kludge
*/
: closed(false),
ownsFile(false),
{
if (!outf) {
throw StreamException(err);
}
}
/**
*
*/
: closed(false),
ownsFile(true),
{
//get information from uri
//printf("out schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
switch (scheme) {
case SCHEME_FILE:
//printf("out path:'%s'\n", cpath);
//outf = fopen(cpath, "wb");
if (!outf) {
throw StreamException(err);
}
break;
case SCHEME_DATA:
data = "data:";
break;
}//switch
}
/**
*
*/
{
close();
}
/**
* Closes this output stream and releases any system resources
* associated with this stream.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return;
if ( ownsFile )
break;
case SCHEME_DATA:
break;
}//switch
closed = true;
}
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
*/
{
if (closed)
return;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return;
break;
case SCHEME_DATA:
//nothing
break;
}//switch
}
/**
* Writes the specified byte to this output stream.
*/
{
if (closed)
return -1;
unsigned char uch;
switch (scheme) {
case SCHEME_FILE:
if (!outf)
return -1;
throw StreamException(err);
}
break;
case SCHEME_DATA:
break;
}//switch
return 1;
}
/**
*
*/
{
}
/**
*
*/
{
delete outputStream;
}
/**
*
*/
{
outputStream->close();
}
/**
*
*/
{
outputStream->flush();
}
/**
*
*/
{
}
} // namespace IO
} // namespace Inkscape
//#########################################################################
//# E N D O F F I L E
//#########################################################################