CMCore/inc/hgl/io/JavaInputStream.h

72 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef HGL_IO_JAVA_INPUT_STREAM_INCLUDE
#define HGL_IO_JAVA_INPUT_STREAM_INCLUDE
#include<hgl/io/DataInputStream.h>
namespace hgl
{
namespace io
{
/**
* Java数据输入流<br>
* 接口类似于java.io.DataInputStream用于和Java程序进行交互
*/
class JavaInputStream
{
protected:
BEDataInputStream *in;
public:
JavaInputStream(InputStream *is)
{
in=new BEDataInputStream(is);
}
virtual ~JavaInputStream()
{
delete in;
}
int64 read (void *ptr,int size){return in?in->ReadFully(ptr,size):-1;}
int skipBytes (int size) {return in?in->Seek(size,SeekOrigin::Current):-1;}
bool readBoolean (bool &b) {return in?in->ReadBool (b):false;}
bool readByte (int8 &i) {return in?in->ReadInt8 (i):false;}
bool readUnsignedByte (uint8 &i) {return in?in->ReadUint8 (i):false;}
bool readShort (int16 &i) {return in?in->ReadInt16 (i):false;}
bool readUnsignedShort (uint16 &i) {return in?in->ReadUint16 (i):false;}
bool readInt (int32 &i) {return in?in->ReadInt32 (i):false;}
bool readLong (int64 &i) {return in?in->ReadInt64 (i):false;}
bool readFloat (float &f) {return in?in->ReadFloat (f):false;}
bool readDouble (double &d) {return in?in->ReadDouble (d):false;}
bool readChar (u16char &c)
{
if(!in)
return(false);
uint16 c16;
if(!in->Read(c16))
return(false);
c=BigToCurrentEndian(c16);
return(true);
}
bool readChars (u16char *wstr,const int count)
{
return in?in->ReadUTF16BEChars(wstr,count):false;
}
bool readUTF (U16String &str)
{
return in?in->ReadUTF8ShortString(str):false;
}
};//class JavaInputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_JAVA_INPUT_STREAM_INCLUDE