CMCore/inc/hgl/io/JavaOutputStream.h

63 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_OUTPUT_STREAM_INCLUDE
#define HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE
#include<hgl/io/DataOutputStream.h>
namespace hgl
{
namespace io
{
/**
* Java数据输出流<br>
* 接口类似于java.io.DataOutputStream用于和Java程序进行交互
*/
class JavaOutputStream
{
protected:
BEDataOutputStream *out;
public:
JavaOutputStream(OutputStream *os)
{
out=new BEDataOutputStream(os);
}
virtual ~JavaOutputStream()
{
delete out;
}
int64 write (const void *ptr,int size) {return out?out->WriteFully(ptr,size):-1;}
bool writeBoolean (const bool &b) {return out?out->WriteBool (b):false;}
bool writeByte (const int8 &i) {return out?out->WriteInt8 (i):false;}
bool writeUnsignedByte (const uint8 &i) {return out?out->WriteUint8 (i):false;}
bool writeShort (const int16 &i) {return out?out->WriteInt16 (i):false;}
bool writeUnsignedShort (const uint16 &i) {return out?out->WriteUint16(i):false;}
bool writeInt (const int32 &i) {return out?out->WriteInt32 (i):false;}
bool writeLong (const int64 &i) {return out?out->WriteInt64 (i):false;}
bool writeFloat (const float &f) {return out?out->WriteFloat (f):false;}
bool writeDouble (const double &d) {return out?out->WriteDouble(d):false;}
bool writeChar (const u16char &c)
{
if(!out)
return(false);
return out->Write(ToBigEndian(c));
}
bool writeChars (const u16char *wstr,const int64 count)
{
return out?out->WriteUTF16BEChars(wstr,count):false;
}
bool writeUTF (const U8String &str){return out?out->WriteUTF8ShortString(str):false;}
bool writeUTF (const U16String &str){return out?out->WriteUTF8ShortString(str):false;}
};//class JavaOutputStream
}//namespace io
}//namespace hgl
#endif//HGL_IO_JAVA_OUTPUT_STREAM_INCLUDE