/*
Write a Java object value into the payload Stream.
<p>
Note that this method only works for the objectified primitive
object types (Integer, Double, Long ...), String's and byte arrays.

Javadoc description supplied by JsJmsMessage interface.
12135
public void writeObject(Object value) throws UnsupportedEncodingException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "writeObject", value);
    getBodyList().add(value);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "writeObject");
  }
780027
public static void serialize(Object value, OutputStream outputStream) throws IOException {
    try {
      new ObjectOutputStream(outputStream).writeObject(value);
    } finally {
      outputStream.close();
    }
  }
1040129
def _write_value(self, field_type, value):
        
        if len(field_type) > 1:
            # We don't need details for arrays and objects
            field_type = field_type[0]

        if field_type == self.TYPE_BOOLEAN:
            self._writeStruct(">B", 1, (1 if value else 0,))
        elif field_type == self.TYPE_BYTE:
            self._writeStruct(">b", 1, (value,))
        elif field_type == self.TYPE_CHAR:
            self._writeStruct(">H", 1, (ord(value),))
        elif field_type == self.TYPE_SHORT:
            self._writeStruct(">h", 1, (value,))
        elif field_type == self.TYPE_INTEGER:
            self._writeStruct(">i", 1, (value,))
        elif field_type == self.TYPE_LONG:
            self._writeStruct(">q", 1, (value,))
        elif field_type == self.TYPE_FLOAT:
            self._writeStruct(">f", 1, (value,))
        elif field_type == self.TYPE_DOUBLE:
            self._writeStruct(">d", 1, (value,))
        elif field_type == self.TYPE_OBJECT or field_type == self.TYPE_ARRAY:
            if value is None:
                self.write_null()
            elif isinstance(value, JavaEnum):
                self.write_enum(value)
            elif isinstance(value, (JavaArray, JavaByteArray)):
                self.write_array(value)
            elif isinstance(value, JavaObject):
                self.write_object(value)
            elif isinstance(value, JavaString):
                self.write_string(value)
            elif isinstance(value, str):
                self.write_blockdata(value)
            else:
                raise RuntimeError("Unknown typecode: {0}".format(field_type))
        else:
            raise RuntimeError("Unknown typecode: {0}".format(field_type))
1018130
private synchronized void writeObject(java.io.ObjectOutputStream s)
        throws java.io.IOException {
        java.io.ObjectOutputStream.PutField fields = s.putFields();
        fields.put("value", getValue());
        fields.put("count", length());
        fields.put("shared", false);
        s.writeFields();
    }
405955
public static int writeBytes(final BitOutput bitOutput, final int lengthSize, final boolean byteUnsigned,
                                 final int byteSize, final byte[] value)
            throws IOException {
        if (bitOutput == null) {
            throw new NullPointerException("bitOutput is null");
        }
        requireValidSizeInt(true, lengthSize);
        requireValidSizeByte(byteUnsigned, byteSize);
        if (value == null) {
            throw new NullPointerException("value is null");
        }
        final int length = value.length & ((1 << lengthSize) - 1);
        bitOutput.writeInt(true, lengthSize, length);
        for (int i = 0; i < length; i++) {
            bitOutput.writeByte(byteUnsigned, byteSize, value[i]);
        }
        return length;
    }
518982
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "writeObject", out);

        try {
            if (requiresInit)
                lazyInitForReading();

            // If message is in write mode, get data into byte array so that we
            // can restore the output stream during readObject.
            // If message is in read mode, store the offset so that we can skip
            // the input stream during readObject.
            if (isBodyReadOnly()) {
                // read mode
                streamOffset = dataBuffer.length - readStream.available();
            }
            else {
                // write mode
                if (_writeBytes != null) {
                    // SIB0121: If the producer has promised not to modify the payload after set,
                    // _writeBytes will always be null
                    dataBuffer = _writeBytes.toByteArray();
                }
            }
            // Use the default mechanism to write the fields.
            out.defaultWriteObject();
        } catch (IOException e) {
            // No FFDC code needed
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(this, tc, "Error during writeObject", e);
            // pass on
            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "writeObject");
    }
1360962
private void writeObject(final ObjectOutputStream out) throws IOException {
		// write all the non-transient fields
		out.defaultWriteObject();

		// write the non-serializable default value field
		if (defaultValue == null) {
			// we don't have a default value
			out.writeBoolean(false);
		} else {
			// we have a default value
			out.writeBoolean(true);

			byte[] serializedDefaultValue;
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
					DataOutputViewStreamWrapper outView = new DataOutputViewStreamWrapper(baos)) {

				TypeSerializer<T> duplicateSerializer = serializer.duplicate();
				duplicateSerializer.serialize(defaultValue, outView);

				outView.flush();
				serializedDefaultValue = baos.toByteArray();
			}
			catch (Exception e) {
				throw new IOException("Unable to serialize default value of type " +
						defaultValue.getClass().getSimpleName() + ".", e);
			}

			out.writeInt(serializedDefaultValue.length);
			out.write(serializedDefaultValue);
		}
	}
1103190
public void printJavaTypeToObject(String value, JClass javaType)
      throws IOException
  {
    if (javaType.getName().equals("boolean"))
      print("new Boolean(" + value + ")");
    else if (javaType.getName().equals("byte"))
      print("new Byte(" + value + ")");
    else if (javaType.getName().equals("short"))
      print("new Short(" + value + ")");
    else if (javaType.getName().equals("int"))
      print("new Integer(" + value + ")");
    else if (javaType.getName().equals("long"))
      print("new Long(" + value + ")");
    else if (javaType.getName().equals("char"))
      print("String.valueOf(" + value + ")");
    else if (javaType.getName().equals("float"))
      print("new Float(" + value + ")");
    else if (javaType.getName().equals("double"))
      print("new Double(" + value + ")");
    else
      print(value);
  }
1279579
private void writeObject(java.io.ObjectOutputStream s)
      throws java.io.IOException {
    s.defaultWriteObject();

    s.writeDouble(get());
  }
552699
public static <T extends BitWritable> void writeObject(final BitOutput output, final T value) throws IOException {
        if (output == null) {
            throw new NullPointerException("output is null");
        }
        if (value == null) {
            throw new NullPointerException("value is null");
        }
        value.write(output);
    }
1127821
private void writeObject(java.io.ObjectOutputStream out)
        throws java.io.IOException {
        // we just write the textual description to the stream, so we
        // have an implementation-independent streaming format
        out.writeUTF(this.toString());
        out.writeObject(this.locale);
        out.writeInt(this.roundingMode);
    }
257333
@Override
	public void writeByte(byte value) throws JMSException
    {
        try
        {
            getOutput().writeByte(value);
        }
        catch (IOException e)
        {
            throw new FFMQException("Cannot write message body","IO_ERROR",e);
        }
    }
892878
public void printJavaTypeToObject(String value, Class<?> javaType)
      throws IOException
  {
    if (Object.class.isAssignableFrom(javaType))
      print(value);
    else if (javaType.equals(boolean.class))
      print("new Boolean(" + value + ")");
    else if (javaType.equals(byte.class))
      print("new Byte(" + value + ")");
    else if (javaType.equals(short.class))
      print("new Short(" + value + ")");
    else if (javaType.equals(int.class))
      print("new Integer(" + value + ")");
    else if (javaType.equals(long.class))
      print("new Long(" + value + ")");
    else if (javaType.equals(char.class))
      print("String.valueOf(" + value + ")");
    else if (javaType.equals(float.class))
      print("new Float(" + value + ")");
    else if (javaType.equals(double.class))
      print("new Double(" + value + ")");
    else
      print(value);
  }
104772
@Override
  public void write(OutputStream out) throws IOException {
    try {
      valueSerializer = null;

      XMLStreamWriter serializer = factory.createXMLStreamWriter(out,
        "UTF-8");
      serializer.setPrefix(RequestConstants.RESTAPI_PREFIX,
        RequestConstants.RESTAPI_NS);
      serializer.setPrefix(RequestConstants.SEARCH_PREFIX,
        RequestConstants.SEARCH_NS);
      serializer.setPrefix("xsi",
        XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
      serializer.setPrefix("xs", XMLConstants.W3C_XML_SCHEMA_NS_URI);

      serializer.writeStartDocument("utf-8", "1.0");

      serializer.writeStartElement(RequestConstants.RESTAPI_PREFIX,
        "rule", RequestConstants.RESTAPI_NS);

      serializer.writeStartElement(RequestConstants.RESTAPI_PREFIX,
        "name", RequestConstants.RESTAPI_NS);
      serializer.writeCharacters(getName());
      serializer.writeEndElement();

      serializer.writeStartElement(RequestConstants.RESTAPI_PREFIX,
        "description", RequestConstants.RESTAPI_NS);
      String description = getDescription();
      if ( description != null ) serializer.writeCharacters(description);
      serializer.writeEndElement();
      serializer.flush();

      // logger.debug("Send: " + new String(queryPayload));
      XMLEventWriter eventWriter = factory.createXMLEventWriter(out);
      for (XMLEvent event : this.queryPayload) {
        eventWriter.add(event);
      }
      eventWriter.flush();
      out.flush();

      writeMetadataElement(serializer);

      serializer.writeEndElement();
      serializer.writeEndDocument();
    } catch (XMLStreamException e) {
      throw new MarkLogicIOException("Failed to serialize rule", e);
    } catch (TransformerFactoryConfigurationError e) {
      throw new MarkLogicIOException("Failed to serialize rule", e);
    } catch (TransformerException e) {
      throw new MarkLogicIOException("Failed to serialize rule", e);
    } finally {
      valueSerializer = null;
    }

  }
161428
private void writeObject(ObjectOutputStream stream) throws IOException {

        stream.defaultWriteObject();

        // not all values in the property bag are going to be serializable; we
        // need to be careful which parts of the bag we serialize
        //
        Map<Object, Object> tempProperties = new HashMap<Object, Object>();
        for (Object key : this.properties.keySet()) {
            Object value = this.properties.get(key);

            if (value instanceof Serializable || value instanceof Externalizable) {

                tempProperties.put(key, value);
            } else {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "value for key \"" + key + "\" is not serializable");
                }
            }
        }

        stream.writeObject(tempProperties);
    }
68169
@Override
    public void writeToObject(Object object) {
        try {
            Method method = BeanUtils.getWriteMethod(object.getClass(), getName());
            if (method != null) {
                method.invoke(object, new Object[]{getValue()});
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
1097547
@Override
	public void writeFloat(float value) throws JMSException
    {
        try
        {
            getOutput().writeFloat(value);
        }
        catch (IOException e)
        {
            throw new FFMQException("Cannot write message body","IO_ERROR",e);
        }
    }