Write a Couchbase document
@param key Couchbase document ID
@param document Couchbase document value
@throws IOException in case of issues while writing to a file
427903
public void write(String key, String document) throws IOException {
    try {
      // Write the key.
      outputStream.write(key.getBytes("UTF-8"));

      // Write the key-document keyDocumentDelimiter.
      outputStream.write(keyDocumentDelimiter.getBytes("UTF-8"));

      // Write the document.
      outputStream.write(document.getBytes("UTF-8"));

      // Write the row keyDocumentDelimiter.
      outputStream.write(rowDelimiter.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) { LOGGER.error("Shouldn't happen."); }
  }
908218
public void write(Node node) {
        
        // is there anything to do?
        if (node == null) {
            return;
        }
        
        short type = node.getNodeType();
        switch (type) {
            case Node.DOCUMENT_NODE: {
                Document document = (Document)node;
                fXML11 = false; //"1.1".equals(getVersion(document));
                if (!fCanonical) {
                    if (fXML11) {
                        fOut.println("<?xml version=\"1.1\" encoding=\"UTF-8\"?>");
                    } else {
                        fOut.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                    }
                    fOut.flush();
                    write(document.getDoctype());
                }
                write(document.getDocumentElement());
                break;
            }
            
            case Node.DOCUMENT_TYPE_NODE: {
                DocumentType doctype = (DocumentType)node;
                fOut.print("<!DOCTYPE ");
                fOut.print(doctype.getName());
                String publicId = doctype.getPublicId();
                String systemId = doctype.getSystemId();
                if (publicId != null) {
                    fOut.print(" PUBLIC '");
                    fOut.print(publicId);
                    fOut.print("' '");
                    fOut.print(systemId);
                    fOut.print('\'');
                } else if (systemId != null) {
                    fOut.print(" SYSTEM '");
                    fOut.print(systemId);
                    fOut.print('\'');
                }
                String internalSubset = doctype.getInternalSubset();
                if (internalSubset != null) {
                    fOut.println(" [");
                    fOut.print(internalSubset);
                    fOut.print(']');
                }
                fOut.println('>');
                break;
            }
            
            case Node.ELEMENT_NODE: {
                fOut.print('<');
                fOut.print(node.getNodeName());
                Attr attrs[] = sortAttributes(node.getAttributes());
                for (int i = 0; i < attrs.length; i++) {
                    Attr attr = attrs[i];
                    fOut.print(' ');
                    fOut.print(attr.getNodeName());
                    fOut.print("=\"");
                    normalizeAndPrint(attr.getNodeValue(), true);
                    fOut.print('"');
                }
                fOut.print('>');
                fOut.flush();
                
                Node child = node.getFirstChild();
                while (child != null) {
                    write(child);
                    child = child.getNextSibling();
                }
                break;
            }
            
            case Node.ENTITY_REFERENCE_NODE: {
                if (fCanonical) {
                    Node child = node.getFirstChild();
                    while (child != null) {
                        write(child);
                        child = child.getNextSibling();
                    }
                } else {
                    fOut.print('&');
                    fOut.print(node.getNodeName());
                    fOut.print(';');
                    fOut.flush();
                }
                break;
            }
            
            case Node.CDATA_SECTION_NODE: {
                if (fCanonical) {
                    normalizeAndPrint(node.getNodeValue(), false);
                } else {
                    fOut.print("<![CDATA[");
                    fOut.print(node.getNodeValue());
                    fOut.print("]]>");
                }
                fOut.flush();
                break;
            }
            
            case Node.TEXT_NODE: {
                normalizeAndPrint(node.getNodeValue(), false);
                fOut.flush();
                break;
            }
            
            case Node.PROCESSING_INSTRUCTION_NODE: {
                fOut.print("<?");
                fOut.print(node.getNodeName());
                String data = node.getNodeValue();
                if (data != null && data.length() > 0) {
                    fOut.print(' ');
                    fOut.print(data);
                }
                fOut.print("?>");
                fOut.flush();
                break;
            }
            
            case Node.COMMENT_NODE: {
                if (!fCanonical) {
                    fOut.print("<!--");
                    String comment = node.getNodeValue();
                    if (comment != null && comment.length() > 0) {
                        fOut.print(comment);
                    }
                    fOut.print("-->");
                    fOut.flush();
                }
            }
        }
        
        if (type == Node.ELEMENT_NODE) {
            fOut.print("</");
            fOut.print(node.getNodeName());
            fOut.print('>');
            fOut.flush();
        }
        
    }
865303
void writeInterPropertyLinks(PropertyDocument document)
			throws RDFHandlerException {
		Resource subject = this.rdfWriter.getUri(document.getEntityId()
				.getIri());
		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_DIRECT_CLAIM_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.DIRECT));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_CLAIM_PROP), Vocabulary.getPropertyUri(
				document.getEntityId(), PropertyContext.STATEMENT));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_STATEMENT_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.VALUE_SIMPLE));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_STATEMENT_VALUE_PROP),
				Vocabulary.getPropertyUri(document.getEntityId(),
						PropertyContext.VALUE));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_QUALIFIER_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.QUALIFIER_SIMPLE));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_QUALIFIER_VALUE_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.QUALIFIER));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_REFERENCE_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.REFERENCE_SIMPLE));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_REFERENCE_VALUE_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.REFERENCE));

		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_NO_VALUE_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.NO_VALUE));
		this.rdfWriter.writeTripleUriObject(subject, this.rdfWriter
				.getUri(Vocabulary.WB_NO_QUALIFIER_VALUE_PROP), Vocabulary
				.getPropertyUri(document.getEntityId(),
						PropertyContext.NO_QUALIFIER_VALUE));
		// TODO something more with NO_VALUE
	}
891136
public void add(DOCUMENT doc) {
      if (doc != null) {
         documents.add(doc);
         int id = documents.size() - 1;
         for (KEY key : documentMapper.apply(doc)) {
            index.put(key, id);
         }
      }
   }
1013881
public static void writeXML(Document xmldocument, Writer writer) throws IOException {
		assert xmldocument != null : AssertMessages.notNullParameter(0);
		assert writer != null : AssertMessages.notNullParameter(1);
		writeNode(xmldocument, writer);
	}
860592
public void write(ObjectWriter out, PersistedPropertyData propData) throws IOException
   {
      // write id
      out.writeInt(SerializationConstants.PERSISTED_PROPERTY_DATA);

      out.writeString(propData.getQPath().getAsString());
      out.writeString(propData.getIdentifier());

      if (propData.getParentIdentifier() != null)
      {
         out.writeByte(SerializationConstants.NOT_NULL_DATA);
         out.writeString(propData.getParentIdentifier());
      }
      else
         out.writeByte(SerializationConstants.NULL_DATA);

      out.writeInt(propData.getPersistedVersion());
      // -------------------

      out.writeInt(propData.getType());
      out.writeBoolean(propData.isMultiValued());
      out.writeLong(propData.getPersistedSize());

      List<ValueData> values = propData.getValues();
      if (values != null)
      {
         out.writeByte(SerializationConstants.NOT_NULL_DATA);
         int listSize = values.size();
         out.writeInt(listSize);
         PersistedValueDataWriter wr = new PersistedValueDataWriter();
         for (int i = 0; i < listSize; i++)
         {
            wr.write(out, (PersistedValueData)values.get(i));
         }
      }
      else
      {
         out.writeByte(SerializationConstants.NULL_DATA);
      }

   }
122688
public void writeContent(final OutputStream result) throws IOException
    {
    	result.write(OPEN_GROUP);
		result.write(INFO_GROUP);
		for(int i = 0; i < infoElements.size(); i++) {
			RtfInfoElement infoElement = (RtfInfoElement) infoElements.get(i);
			infoElement.writeContent(result);
		}
		
		// handle document protection
    	if(document.getDocumentSettings().isDocumentProtected()) {
	    	result.write(OPEN_GROUP);
			result.write(INFO_PASSWORD);
			result.write(DELIMITER);
			result.write(document.getDocumentSettings().getProtectionHashBytes());
			result.write(CLOSE_GROUP);
    	}

		result.write(CLOSE_GROUP);
		this.document.outputDebugLinebreak(result);
    }
313365
protected JsonWriter property(String key, Iterable<?> iterable) throws IOException {
      Preconditions.checkArgument(!inArray(), "Cannot write a property inside an array.");
      beginArray(key);
      for (Object o : iterable) {
         value(o);
      }
      endArray();
      return this;
   }
956604
public void store(Document doc, File file) throws IOException {
	store(doc, ResourceUtil.toResource(file));
    }
581944
public static void cache(XmlFileModel key, Document document)
    {
        String cacheKey = getKey(key);
        map.put(cacheKey, new CacheDocument(false, document));
    }
676837
public static void writeXML(Document xmldocument, OutputStream stream) throws IOException {
		assert xmldocument != null : AssertMessages.notNullParameter(0);
		assert stream != null : AssertMessages.notNullParameter(1);
		writeNode(xmldocument, stream);
	}
293505
public void setRtfDocument(RtfDocument doc) {
        this.document = doc;
        if(headerAll != null) {
            headerAll.setRtfDocument(this.document);
        }
        if(headerFirst != null) {
            headerFirst.setRtfDocument(this.document);
        }
        if(headerLeft != null) {
            headerLeft.setRtfDocument(this.document);
        }
        if(headerRight != null) {
            headerRight.setRtfDocument(this.document);
        }
    }
917163
public void write(Model project, Document document, Writer writer, Format jdomFormat) throws java.io.IOException
   {
      updateModel(project, "project", new Counter(0), document.getRootElement());

      XMLOutputter outputter = new XMLOutputter();
      outputter.setFormat(jdomFormat);
      outputter.output(document, writer);
   }
173024
public void writeXmlDocument(Document document, File file) throws IOException {
        try {
            Transformer tr = transformerFactory.newTransformer();
            tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            tr.setOutputProperty(OutputKeys.INDENT, "yes");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            tr.transform(new DOMSource(document), new StreamResult(fileOutputStream));
            fileOutputStream.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage(), e);
        }
    }
465396
@Override
    public void writeText(PDDocument doc, Writer outputStream) throws IOException
    {
        try
        {
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
            LSSerializer writer = impl.createLSSerializer();
            LSOutput output = impl.createLSOutput();
            writer.getDomConfig().setParameter("format-pretty-print", true);
            output.setCharacterStream(outputStream);
            createDOM(doc);
            writer.write(getDocument(), output);
        } catch (ClassCastException e) {
            throw new IOException("Error: cannot initialize the DOM serializer", e);
        } catch (ClassNotFoundException e) {
            throw new IOException("Error: cannot initialize the DOM serializer", e);
        } catch (InstantiationException e) {
            throw new IOException("Error: cannot initialize the DOM serializer", e);
        } catch (IllegalAccessException e) {
            throw new IOException("Error: cannot initialize the DOM serializer", e);
        }
    }
1266130
void writeDocument(OutputStream outStream, Document doc) {
        DOMImplementationRegistry domRegistry = null;
        try {
            domRegistry = DOMImplementationRegistry.newInstance();
        // Fortify Mod: Broaden try block to capture all potential exceptions
        // } catch (Exception e) {
        //    LOGR.warning(e.getMessage());
        // }
        DOMImplementationLS impl = (DOMImplementationLS) domRegistry
                .getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        writer.getDomConfig().setParameter("xml-declaration", false);
        writer.getDomConfig().setParameter("format-pretty-print", true);
        LSOutput output = impl.createLSOutput();
        output.setEncoding("UTF-8");
        output.setByteStream(outStream);
        writer.write(doc, output);
        } catch (Exception e) {
            LOGR.warning(e.getMessage());
        }
    }
987431
public Document removeDocument(String key) throws PrintingException {
		if (documentMap.containsKey(key)) {
			return documentMap.remove(key);
		} else {
			throw new PrintingException(PrintingException.DOCUMENT_NOT_FOUND, key);
		}
	}