Serializes a XML document to a byte array.
@param n the XML document
@throws java.io.IOException on error
@return the serialized XML document
328194
public static byte[] serializeDoc(Node n) throws IOException {
        XmlDomWriter xw = new XmlDomWriter();
        ByteArrayOutputStream fout = new ByteArrayOutputStream();
        xw.setOutput(fout, null);
        xw.setCanonical(false);
        xw.write(n);
        fout.close();
        return fout.toByteArray();
    }
237772
public StringBuffer readFile(String filename) throws IOException {
		BufferedReader reader = new BufferedReader(new FileReader(filename));
		StringBuffer xml = new StringBuffer();
		String line = null;
        while((line = reader.readLine()) != null){
            xml.append(line);
        }
		reader.close();
		return xml;
	}
65266
public static <T> byte[] toByteArray(T message, Schema<T> schema,
            XMLOutputFactory outFactory)
    {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        try
        {
            writeTo(out, message, schema, outFactory);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
        return out.toByteArray();
    }
424097
protected byte[] serialize(Object o) {
    if (o == null) {
      throw new NullPointerException("Can't serialize null");
    }
    byte[] rv=null;
    ByteArrayOutputStream bos = null;
    ObjectOutputStream os = null;
    try {
      bos = new ByteArrayOutputStream();
      os = new ObjectOutputStream(bos);
      os.writeObject(o);
      os.close();
      bos.close();
      rv = bos.toByteArray();
    } catch (IOException e) {
      throw new IllegalArgumentException("Non-serializable object", e);
    } finally {
      CloseUtil.close(os);
      CloseUtil.close(bos);
    }
    return rv;
  }
745677
public static String serialize(String xmlString) {
        Writer sw = new StringBuilderWriter();
        serialize(asStreamSource(xmlString), sw);
        return sw.toString();
    }
686069
@JsonProperty("n")
    @JsonSerialize(using = Base64UrlJsonSerializer.class)
    @JsonDeserialize(using = Base64UrlJsonDeserializer.class)
    public byte[] n() {
        return ByteExtensions.clone(this.n);
    }
250692
@Override
  public void writeInt(int n) throws IOException {
    byte[] intBytes = new byte[] { (byte) ((n >>> 24) ^ 0x80),
        (byte) (n >>> 16), (byte) (n >>> 8), (byte) n };
    out.write(intBytes);
  }
1303689
public String toXML() {
        Error error = getError();

        if (error != null) {
            return error.toXML();
        }

        StringWriter sw = new StringWriter();
        String xml = "";

        try {
            JAXBContext context = JAXBContext.newInstance(this.getClass());
            Marshaller marshaller = context.createMarshaller();

            marshaller.marshal(this, sw);
            xml = sw.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xml;
    }
257798
public static final Object deserialize(byte[] bytes) throws Exception {
		if (bytes == null || bytes.length < 4) {
			return new LinkedHashMap<>();
		}

		// Try to deserialize content as Object (type-safe serialization)
		if (bytes[0] == 1) {
			try {
				ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
				bais.skip(1);
				return new ObjectInputStream(bais).readObject();
			} catch (Throwable ignored) {
			}
		}

		// Read content as JSON
		String json = new String(Arrays.copyOfRange(bytes, 1, bytes.length), StandardCharsets.UTF_8);
		return TreeReaderRegistry.getReader(null).parse(json);
	}
1237274
public String encode(XML xml) throws ParserException, SAXException, IOException {

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;

        InputSource is = new InputSource(new StringReader(xml.toString()));

        try {
            builder = dbFactory.newDocumentBuilder();
            Document doc = builder.parse(is);
            return net.arnx.jsonic.JSON.encode(doc, true);
        } catch (SAXException e) {
            throw new ParserException(e.getMessage());
        } catch (ParserConfigurationException e) {
            throw new ParserException(e.getMessage());
        }
    }
110684
public byte[] readBytes()
        throws IOException
    {
        int tag = is.read();

        if (tag == 'N')
            return null;

        if (tag != 'B')
            throw expect("bytes", tag);

        int b16 = is.read();
        int b8 = is.read();

        int len = (b16 << 8) + b8;

        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        for (int i = 0; i < len; i++)
            bos.write(is.read());

        return bos.toByteArray();
    }
503837
public byte[] toByteArray() throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(this);
        return byteOut.toByteArray();
    }
930817
private static String encode(byte[] bytes) {
        try {
            if (System.getProperty("java.version").startsWith("1.")) {
                // return DatatypeConverter.printBase64Binary(str);
                Class<?> DatatypeConverter = Class.forName("javax.xml.bind.DatatypeConverter");
                return (String) DatatypeConverter.getMethod("printBase64Binary", byte[].class).invoke(null, bytes);
            } else {
                // return Base64.getEncoder().encode();
                Class<?> Base64 = Class.forName("java.util.Base64");
                Object encodeObject = Base64.getMethod("getEncoder").invoke(null);
                return (String) encodeObject.getClass().getMethod("encodeToString", byte[].class).invoke(encodeObject, bytes);
            }
        } catch (Exception e) {
            return null;
        }
    }
18679
@Override
	public Document readXML() {
		final String xmlString = readString();
		Document doc = null;
		try {
			doc = XMLUtils.stringToDoc(xmlString);
		} catch (IOException ioex) {
			log.error("IOException converting xml to dom", ioex);
		}
		storeReference(doc);
		return doc;
	}
77303
def tostring(node, indent=4, nsmap=None):
    
    out = io.BytesIO()
    writer = StreamingXMLWriter(out, indent, nsmap=nsmap)
    writer.serialize(node)
    return out.getvalue()
52355
public byte[] convertToXmlByteArray(BucketVersioningConfiguration versioningConfiguration) {
        XmlWriter xml = new XmlWriter();
        xml.start("VersioningConfiguration", "xmlns", Constants.XML_NAMESPACE);
        xml.start("Status").value(versioningConfiguration.getStatus()).end();

        Boolean mfaDeleteEnabled = versioningConfiguration.isMfaDeleteEnabled();
        if (mfaDeleteEnabled != null) {
            if (mfaDeleteEnabled) {
                xml.start("MfaDelete").value("Enabled").end();
            } else {
                xml.start("MfaDelete").value("Disabled").end();
            }
        }

        xml.end();

        return xml.getBytes();
    }
366043
public static byte[] serialize(Serializable s) throws IOException {

        HsqlByteArrayOutputStream bo = new HsqlByteArrayOutputStream();
        ObjectOutputStream        os = new ObjectOutputStream(bo);

        os.writeObject(s);

        return bo.toByteArray();
    }