В C ++ я создал класс под названием Serializer.И я хочу дублировать функциональность в Java.Вот как работает Serializer.
Serializer s;
s.writeString(myString); // automatically converted to Big-Endian unicode string with length prepended.
s.writeInt(myInt); // automatically converted to Big-Endian integer (swizzled if necessary)
s.writeObject(myObject); // which implements the Serializable interface
{
s.writeInt(myObjectId); // internally, it writes the data that I want to serialize.
...
}
ZlibCompressor.compress(s); // 's' is compressed
{
bytes = s.getBytes(); // internally, it gets bytes, ...
compressFunc(bytes); // compress them
s.overwrite(bytes); // and overwrites
}
AESCipher.encrypt(s); // similarly, 's' is encrypted
// and the reverse in the same file, using the same all-in-one class to manipulate byte data.
AESCipher.decrypt(s);
ZlibCompressor.decompress(s);
s.readString(myString);
s.readInt(myInt);
s.readObject(myObject);
И, конечно, это еще несколько функций, которые вы можете выполнять (копировать и вставлять из C ++):
ByteArray Split(const Uint32& start, const Uint32& size);
inline Uint32 GetSize() const { return mBytes.size(); }
inline const Uint32& GetPos() const { return mPos; }
inline Bool IsEmpty() const { return mBytes.empty(); }
inline const Bool& IsError() const { return mError; }
inline void Resize(const Uint32& size, const Byte& val = 0) { mBytes.resize(size, val); }
inline void SetPos(const Uint32& pos) const { mPos = pos; }
inline void Reset() const { mPos = 0; mError = false; }
inline void Clear() { mBytes.clear(); Reset(); }
inline void Push(const Byte& x) { mBytes.push_back(x); }
inline void Pop() { mBytes.pop_back(); }
- Есть ливстроенный класс, который делает это, свободно способен манипулировать байтовыми данными?
- Если нет, можете ли вы использовать поток ввода и вывода вместе?
- Если вы не можете, то каквы конвертируете между InputStream и OutputStream?
- Есть ли другой способ решения этой проблемы?
Примечание: все байтовые данные могут находиться в памяти.Память не проблема.
Спасибо.