فئة Java.io.ObjectOutputStream في Java | مجموعة 1 المزيد من الطرق:
الكتابة باطلة (بايت [] buf):
Writes an array of bytes. This method will block until the byte is actually written.
Syntax : public void write(byte[] buf) throws IOException Parameters: buf - the data to be written Throws: IOException
كتابة باطلة (بايت [] buf int off int len):
Writes a sub array of bytes.
Syntax : public void write(byte[] buf int off int len) throws IOException Parameters: buf - the data to be written off - the start offset in the data len - the number of bytes that are written Throws: IOException
كتابة باطلة (int val):
Writes a byte. This method will block until the byte is actually written.
Syntax : public void write(int val) throws IOException Parameters: val - the byte to be written to the stream Throws: IOException
كتابة فارغة Boolean (قيمة منطقية):
Writes a boolean.
Syntax : public void writeBoolean(boolean val) throws IOException Parameters: val - the boolean to be written Throws: IOException
كتابة باطلة (int val):
Writes an 8 bit byte.
Syntax : public void writeByte(int val) throws IOException Parameters: val - the byte value to be written Throws: IOException
بايتات الكتابة باطلة (سلسلة str):
Writes a String as a sequence of bytes.
Syntax : public void writeBytes(String str) throws IOException Parameters: str - the String of writeBytes to be written Throws: IOException
كتابة فارغة (int val):
Writes a 16 bit char.
Syntax : public void writeChar(int val) throws IOException Parameters: val - the char value to be written Throws: IOException
الكتابة الفارغة (سلسلة سلسلة):
Writes a String as a sequence of chars.
Syntax : public void writeChars(String str) throws IOException Parameters: str - the String of chars to be written Throws: IOException
Write the specified class descriptor to the ObjectOutputStream. Class descriptors are used to identify the classes of objects written to the stream. Subclasses of ObjectOutputStream may override this method to customize the way in which class descriptors are written to the serialization stream. The corresponding method in ObjectInputStream readClassDescriptor should then be overridden to reconstitute the class descriptor from its custom stream representation. By default this method writes class descriptors according to the format defined in the Object Serialization specification.
Syntax : protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException Parameters: desc - class descriptor to write to the stream Throws: IOException
كتابة فارغة مزدوجة (فال مزدوج):
Writes a 64 bit double.
Syntax : public void writeDouble(double val) throws IOException Parameters: val - the double value to be written Throws: IOException
حقول الكتابة الفارغة ():
Write the buffered fields to the stream.
Syntax : public void writeFields() throws IOException Throws: IOException NotActiveException
كتابة فارغة (تعويم فال):
Writes a 32 bit float.
Syntax : public void writeFloat(float val) throws IOException Parameters: val - the float value to be written Throws: IOException
كتابة باطلة (int val):
Writes a 32 bit int.
Syntax : public void writeInt(int val) throws IOException Parameters: val - the integer value to be written Throws: IOException
كتابة فارغة طويلة (فال طويل):
Writes a 64 bit long.
Syntax : public void writeLong(long val) throws IOException Parameters: val - the long value to be written Throws: IOException
كائن الكتابة باطلة (كائن الكائن):
Write the specified object to the ObjectOutputStream.The class of the object the signature of the class and the values of the non-transient and non-static fields of the class and all of its supertypes are written. Default serialization for a class can be overridden using the writeObject and the readObject methods. Objects referenced by this object are written transitively so that a complete equivalent graph of objects can be reconstructed by an ObjectInputStream.
Syntax : public final void writeObject(Object obj) throws IOException Parameters: obj - the object to be written Throws: InvalidClassException NotSerializableException IOException
writeObjectOverride باطلة محمية (Object obj):
Method used by subclasses to override the default writeObject method. This method is called by trusted subclasses of ObjectInputStream that constructed ObjectInputStream using the protected no-arg constructor. The subclass is expected to provide an override method with the modifier 'final'.
Syntax : protected void writeObjectOverride(Object obj) throws IOException Parameters: obj - object to be written to the underlying stream Throws: IOException
كتابة فارغة (int val):
Writes a 16 bit short.
Syntax : public void writeShort(int val) throws IOException Parameters: val - the short value to be written Throws: IOException
كتابة الفراغ المحميStreamHeader() :
The writeStreamHeader method is provided so subclasses can append or prepend their own header to the stream.It writes the magic number and version to the stream.
يكتب كائنًا "غير مشترك" إلى ObjectOutputStream. هذا التابع مطابق لـ writeObject فيما عدا أنه يكتب دائمًا الكائن المحدد ككائن فريد جديد في الدفق (على عكس المرجع الخلفي الذي يشير إلى مثيل متسلسل مسبقًا). خاصة:
يتم دائمًا إجراء تسلسل للكائن المكتوب عبر writeUnshared بنفس طريقة الكائن الذي يظهر حديثًا (كائن لم تتم كتابته في الدفق بعد) بغض النظر عما إذا كان الكائن قد تمت كتابته مسبقًا أم لا.
إذا تم استخدام writeObject لكتابة كائن تمت كتابته مسبقًا باستخدام writeUnshared، فسيتم التعامل مع عملية writeUnshared السابقة كما لو كانت كتابة لكائن منفصل. بمعنى آخر، لن يقوم ObjectOutputStream أبدًا بإنشاء مراجع خلفية لبيانات الكائن المكتوبة عن طريق استدعاءات writeUnshared.
While writing an object via writeUnshared does not in itself guarantee a unique reference to the object when it is deserialized it allows a single object to be defined multiple times in a stream so that multiple calls to readUnshared by the receiver will not conflict. Note that the rules described above only apply to the base-level object written with writeUnshared and not to any transitively referenced sub-objects in the object graph to be serialized. ObjectOutputStream subclasses which override this method can only be constructed in security contexts possessing the 'enableSubclassImplementation' SerializablePermission; any attempt to instantiate such a subclass without this permission will cause a SecurityException to be thrown.
Syntax : public void writeUnshared(Object obj) throws IOException Parameters: obj - object to write to stream Throws: NotSerializableException InvalidClassException IOException
كتابة باطلةUTF (سلسلة str):
Primitive data write of this String in modified UTF-8 format.Note that there is a significant difference between writing a String into the stream as primitive data or as an Object. A String instance written by writeObject is written into the stream as a String initially. Future writeObject() calls write references to the string into the stream.
Syntax : public void writeUTF(String str) throws IOException Parameters: str - the String to be written Throws: IOException
تدفق الفراغ () :
Flushes the stream. This will write any buffered output bytes and flush through to the underlying stream.
Syntax : public void flush() throws IOException Throws: IOException
//Java program illustrating ObjectOutputStream//write methodsimportjava.io.*;classObjectOutputStreamDemo{publicstaticvoidmain(String[]args)throwsIOExceptionClassNotFoundException{FileOutputStreamout=newFileOutputStream('file.txt');ObjectOutputStreamoout=newObjectOutputStream(out);oout.writeObject(newdemo());//illustrating writeUnshared()//Writes an 'unshared' object to the ObjectOutputStream.oout.writeUnshared(14);//flush the streamoout.flush();oout.close();FileInputStreamfin=newFileInputStream('file.txt');ObjectInputStreamois=newObjectInputStream(fin);// read an object from the stream and cast it to demodemoobj=(demo)ois.readObject();System.out.println(obj.var);System.out.println(ois.readUnshared());}}classdemoimplementsSerializable{staticintvar= 25;// assign a new serialPersistentFieldsprivatestaticfinalObjectStreamField[]serialPersistentFields={newObjectStreamField('var'Integer.TYPE)};privatevoidreadObject(ObjectInputStreamin)throwsIOExceptionClassNotFoundException{// makes them available by name.ObjectInputStream.GetFieldfields=in.readFields();//Get the value of the named int field from the persistent field.var= fields.get('var'0);}privatevoidwriteObject(ObjectOutputStreamout)throwsIOException{// write into the ObjectStreamField array the variable stringObjectOutputStream.PutFieldfields=out.putFields();fields.put('var'var);//Write the buffered fields to the streamout.writeFields();}}