Write key definition XML configuration file

@param keydefFile key definition file
@param keydefs list of key definitions
@throws DITAOTException if writing configuration file failed
183382
public static void writeKeydef(final File keydefFile, final Collection<KeyDef> keydefs) throws DITAOTException {
        XMLStreamWriter keydef = null;
        try (OutputStream out = new FileOutputStream(keydefFile)) {
            keydef = XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8");
            keydef.writeStartDocument();
            keydef.writeStartElement(ELEMENT_STUB);
            for (final KeyDef k : keydefs) {
                keydef.writeStartElement(ELEMENT_KEYDEF);
                keydef.writeAttribute(ATTRIBUTE_KEYS, k.keys);
                if (k.href != null) {
                    keydef.writeAttribute(ATTRIBUTE_HREF, k.href.toString());
                }
                if (k.scope != null) {
                    keydef.writeAttribute(ATTRIBUTE_SCOPE, k.scope);
                }
                if (k.format != null) {
                    keydef.writeAttribute(ATTRIBUTE_FORMAT, k.format);
                }
                if (k.source != null) {
                    keydef.writeAttribute(ATTRIBUTE_SOURCE, k.source.toString());
                }
                keydef.writeEndElement();
            }
            keydef.writeEndDocument();
        } catch (final XMLStreamException | IOException e) {
            throw new DITAOTException("Failed to write key definition file " + keydefFile + ": " + e.getMessage(), e);
        } finally {
            if (keydef != null) {
                try {
                    keydef.close();
                } catch (final XMLStreamException e) {
                }
            }
        }
    }
1030084
public void write(XMLStreamWriter writer, AttributeDefinition<?> def, String name) throws XMLStreamException {
      Attribute<?> attribute = attribute(def);
      attribute.write(writer, name);
   }
872788
public static void writeToFile(final File fileNode, final byte[] data) throws FrameworkException, IOException {

		setFileProperties(fileNode);

		FileUtils.writeByteArrayToFile(fileNode.getFileOnDisk(), data);

	}
129224
public void write(EntityType type) throws ODataRenderException {

        LOG.debug("Writing type {} of type {}", type.getName(), type.getMetaType());
        try {
            xmlWriter.writeStartElement(ENTITY_TYPE);
            if (!isNullOrEmpty(type.getBaseTypeName())) {
                xmlWriter.writeAttribute(BASE_TYPE, type.getBaseTypeName());
            }
            if (type.isOpen()) {
                xmlWriter.writeAttribute(OPEN_TYPE, Boolean.toString(type.isOpen()));
            }
            if (type.hasStream()) {
                xmlWriter.writeAttribute(HAS_STREAM, Boolean.toString(type.hasStream()));
            }
            xmlWriter.writeAttribute(NAME, type.getName());
            if (type.isAbstract()) {
                xmlWriter.writeAttribute(ABSTRACT, "true");
            }
            xmlWriter.writeStartElement(ENTITY_TYPE_KEY);
            for (PropertyRef propertyRef : type.getKey().getPropertyRefs()) {
                xmlWriter.writeStartElement(PROPERTY_REF);
                xmlWriter.writeAttribute(NAME, propertyRef.getPath());
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndElement();

            visitProperties(entityDataModel, type, property -> {
                try {
                    propertyWriter.write(property);
                } catch (XMLStreamException e) {
                    throw new ODataRenderException("Error while writing property: " + property.getName(), e);
                }
            });
            xmlWriter.writeEndElement();
        } catch (XMLStreamException e) {
            throw new ODataRenderException("Error while writing entity type: " + type.getName(), e);
        }

    }
1236567
protected void writeFile(String basename, T content,
			Function2<? super File, ? super String, ? extends File> outputDirectoryFilter) {
		// Create the file.
		// Encode
		final byte[] bytes = content.toString().getBytes(Charset.forName(getCodeConfig().getEncoding()));
		writeFile(basename, bytes, outputDirectoryFilter);
	}
53548
void writeConfigPropsXml(List<ConfigPropType> props, Writer out, int indent) throws IOException
   {
      if (props == null || props.size() == 0)
         return;
      for (ConfigPropType prop : props)
      {
         writeIndent(out, indent);
         out.write("<config-property>");
         writeEol(out);

         writeIndent(out, indent + 1);
         out.write("<config-property-name>" + prop.getName() + "</config-property-name>");
         writeEol(out);
         writeIndent(out, indent + 1);
         out.write("<config-property-type>java.lang." + prop.getType() + "</config-property-type>");
         writeEol(out);
         writeIndent(out, indent + 1);
         out.write("<config-property-value>" + prop.getValue() + "</config-property-value>");
         writeEol(out);

         writeIndent(out, indent);
         out.write("</config-property>");
         writeEol(out);
         writeEol(out);
      }
   }
907998
private void showKeyspace(PrintStream output, KsDef ksDef)
    {
        output.append("create keyspace ").append(CliUtils.maybeEscapeName(ksDef.name));

        writeAttr(output, true, "placement_strategy", normaliseType(ksDef.strategy_class, "org.apache.cassandra.locator"));

        if (ksDef.strategy_options != null && !ksDef.strategy_options.isEmpty())
        {
            final StringBuilder opts = new StringBuilder();
            opts.append("{");
            String prefix = "";
            for (Map.Entry<String, String> opt : ksDef.strategy_options.entrySet())
            {
                opts.append(prefix).append(CliUtils.escapeSQLString(opt.getKey())).append(" : ").append(CliUtils.escapeSQLString(opt.getValue()));
                prefix = ", ";
            }
            opts.append("}");
            writeAttrRaw(output, false, "strategy_options", opts.toString());
        }

        writeAttr(output, false, "durable_writes", ksDef.durable_writes);

        output.append(";").append(NEWLINE);
        output.append(NEWLINE);

        output.append("use ").append(CliUtils.maybeEscapeName(ksDef.name)).append(";");
        output.append(NEWLINE);
        output.append(NEWLINE);

        Collections.sort(ksDef.cf_defs, new CfDefNamesComparator());
        for (CfDef cfDef : ksDef.cf_defs)
            showColumnFamily(output, cfDef);
        output.append(NEWLINE);
        output.append(NEWLINE);
    }

    /**
     * Creates a CLI script for the CfDef including meta data to the supplied StringBuilder.
     *
     * @param output File to write to.
     * @param cfDef  CfDef to export attributes from.
     */
    private void showColumnFamily(PrintStream output, CfDef cfDef)
    {
        output.append("create column family ").append(CliUtils.maybeEscapeName(cfDef.name));

        writeAttr(output, true, "column_type", cfDef.column_type);
        writeAttr(output, false, "comparator", normaliseType(cfDef.comparator_type, "org.apache.cassandra.db.marshal"));
        if (cfDef.column_type.equals("Super"))
            writeAttr(output, false, "subcomparator", normaliseType(cfDef.subcomparator_type, "org.apache.cassandra.db.marshal"));
        if (!StringUtils.isEmpty(cfDef.default_validation_class))
            writeAttr(output, false, "default_validation_class",
                        normaliseType(cfDef.default_validation_class, "org.apache.cassandra.db.marshal"));
        writeAttr(output, false, "key_validation_class",
                    normaliseType(cfDef.key_validation_class, "org.apache.cassandra.db.marshal"));

        writeAttr(output, false, "read_repair_chance", cfDef.read_repair_chance);
        writeAttr(output, false, "dclocal_read_repair_chance", cfDef.dclocal_read_repair_chance);
        writeAttr(output, false, "gc_grace", cfDef.gc_grace_seconds);
        writeAttr(output, false, "min_compaction_threshold", cfDef.min_compaction_threshold);
        writeAttr(output, false, "max_compaction_threshold", cfDef.max_compaction_threshold);
        writeAttr(output, false, "compaction_strategy", cfDef.compaction_strategy);
        writeAttr(output, false, "caching", cfDef.caching);
        writeAttr(output, false, "cells_per_row_to_cache", cfDef.cells_per_row_to_cache);
        writeAttr(output, false, "default_time_to_live", cfDef.default_time_to_live);
        writeAttr(output, false, "speculative_retry", cfDef.speculative_retry);

        if (cfDef.isSetBloom_filter_fp_chance())
            writeAttr(output, false, "bloom_filter_fp_chance", cfDef.bloom_filter_fp_chance);
        if (!cfDef.compaction_strategy_options.isEmpty())
        {
            StringBuilder cOptions = new StringBuilder();

            cOptions.append("{");

            Map<String, String> options = cfDef.compaction_strategy_options;

            int i = 0, size = options.size();

            for (Map.Entry<String, String> entry : options.entrySet())
            {
                cOptions.append(CliUtils.quote(entry.getKey())).append(" : ").append(CliUtils.quote(entry.getValue()));

                if (i != size - 1)
                    cOptions.append(", ");

                i++;
            }

            cOptions.append("}");

            writeAttrRaw(output, false, "compaction_strategy_options", cOptions.toString());
        }
        if (!StringUtils.isEmpty(cfDef.comment))
            writeAttr(output, false, "comment", cfDef.comment);

        if (!cfDef.column_metadata.isEmpty())
        {
            output.append(NEWLINE)
                  .append(TAB)
                  .append("and column_metadata = [");

            boolean first = true;
            for (ColumnDef colDef : cfDef.column_metadata)
            {
                if (!first)
                    output.append(",");
                first = false;
                showColumnMeta(output, cfDef, colDef);
            }

            output.append("]");
        }

        if (cfDef.compression_options != null && !cfDef.compression_options.isEmpty())
        {
            StringBuilder compOptions = new StringBuilder();

            compOptions.append("{");

            int i = 0, size = cfDef.compression_options.size();

            for (Map.Entry<String, String> entry : cfDef.compression_options.entrySet())
            {
                compOptions.append(CliUtils.quote(entry.getKey())).append(" : ").append(CliUtils.quote(entry.getValue()));

                if (i != size - 1)
                    compOptions.append(", ");

                i++;
            }

            compOptions.append("}");

            writeAttrRaw(output, false, "compression_options", compOptions.toString());
        }
        if (cfDef.isSetIndex_interval())
            writeAttr(output, false, "index_interval", cfDef.index_interval);

        output.append(";");
        output.append(NEWLINE);
        output.append(NEWLINE);
    }
849941
protected void writeVarDef( IVarDef varDef)
    {
    Stream<VarValueDef> values =
      varDef.getValues() == null
      ? null
      : toStream( varDef.getValues());

    Stream<IVarDef> members = 
      varDef.getMembers() == null
      ? null
      : toStream( varDef.getMembers());

    String varTag =
      members == null
      ? VAR_TAG
      : VARSET_TAG;

    ConditionWriter conditionWriter = new ConditionWriter( varDef.getCondition());

    xmlWriter_
      .element( varTag)
      .attribute( NAME_ATR, varDef.getName())
      .attributeIf( WHEN_ATR, conditionWriter.getWhenAttribute())
      .content( () ->
        {
        writeAnnotations( varDef);
        conditionWriter.writeWhenElement();
        if( varTag.equals( VAR_TAG))
          {
          values.forEach( this::writeValue);
          }
        else
          {
          members.forEach( this::writeVarDef);
          }
        })
      .write();
    }
749808
public void writeDiffFile(final Task<Diff> diff)
		throws IOException
	{

		int partsCount;
		int size = diff.size();
		Diff d;
		DiffPart p;
		RevisionCodecData codec;

		this.writer
				.write(WikipediaXMLKeys.KEY_START_PAGE.getKeyword() + "\r\n");

		ArticleInformation header = diff.getHeader();

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_TITLE.getKeyword());
		this.writer.write(header.getArticleName());
		this.writer.write(WikipediaXMLKeys.KEY_END_TITLE.getKeyword() + "\r\n");

		this.writer.write("\t" + WikipediaXMLKeys.KEY_START_ID.getKeyword());
		this.writer.write(Integer.toString(header.getArticleId()));
		this.writer.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

		this.writer.write("\t<partCounter>");
		this.writer.write(Integer.toString(diff.getPartCounter()));
		this.writer.write("</partCounter>\r\n");

		for (int i = 0; i < size; i++) {
			d = diff.get(i);

			this.writer
					.write("\t"
							+ WikipediaXMLKeys.KEY_START_REVISION.getKeyword()
							+ "\r\n");

			codec = d.getCodecData();
			if (!codec.isConverted()) {
				codec.totalSizeInBits();
			}

			this.writer.write("\t\t<codecData>\r\n");

			this.writer.write("\t\t\t<s>"
					+ Integer.toString(codec.getBlocksizeS()) + "</s>\r\n");
			this.writer.write("\t\t\t<e>"
					+ Integer.toString(codec.getBlocksizeE()) + "</e>\r\n");
			this.writer.write("\t\t\t<b>"
					+ Integer.toString(codec.getBlocksizeB()) + "</b>\r\n");
			this.writer.write("\t\t\t<l>"
					+ Integer.toString(codec.getBlocksizeL()) + "</l>\r\n");

			this.writer.write("\t\t</codecData>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(d.getRevisionID()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

			this.writer.write("\t\t<revCount>");
			this.writer.write(Integer.toString(d.getRevisionCounter()));
			this.writer.write("</revCount>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TIMESTAMP.getKeyword());
			this.writer.write(d.getTimeStamp().toString());
			this.writer.write(WikipediaXMLKeys.KEY_END_TIMESTAMP.getKeyword()
					+ "\r\n");

			this.writer.write("\t\t<diff>\r\n");
			partsCount = d.size();
			for (int j = 0; j < partsCount; j++) {

				p = d.get(j);
				this.writer.write("\t\t\t<diffPart>\r\n");

				this.writer.write("\t\t\t\t<action>" + p.getAction()
						+ "</action>\r\n");
				this.writer.write("\t\t\t\t<start>"
						+ Integer.toString(p.getStart()) + "</start>\r\n");
				this.writer.write("\t\t\t\t<end>"
						+ Integer.toString(p.getEnd()) + "</end>\r\n");
				if (p.getText() != null) {
					this.writer
							.write("\t\t\t\t<content xml:space=\"preserve\">"
									+ p.getText());
					this.writer.write("</content>\r\n");
				}

				this.writer.write("\t\t\t</diffPart>\r\n");
			}

			this.writer.write("\t\t</diff>\r\n");
			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_END_REVISION.getKeyword() + "\r\n");
		}

		this.writer.write(WikipediaXMLKeys.KEY_END_PAGE.getKeyword() + "\r\n");
		this.writer.flush();
	}
283030
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
    {
        $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
            array(
                'textRows' => $storageDef->dataInt1,
            )
        );
        $fieldDef->defaultValue->data = null;
        $fieldDef->defaultValue->sortKey = '';
    }
389738
public void transform(final File inputFile, final File outputFile, final List<XMLFilter> filters) throws DITAOTException {
        if (inputFile.equals(outputFile)) {
            transform(inputFile, filters);
        } else {
            transformFile(inputFile, outputFile, filters);
        }
    }
849138
public function write(array $schemaFiles, string $extension, string $outputDirectory): void
    {
        foreach ($schemaFiles as $schemaFilename => $bundleSchema) {
            $filename = $this->generateFilename($bundleSchema, $extension, $outputDirectory);
            $this->writePopo($bundleSchema, $filename);
        }
    }
1297348
function writeXf()
	{
		// Set the type of the XF record and some of the attributes.
		if ($this->_isStyleXf) {
			$style = 0xFFF5;
		} else {
			$style   = self::_mapLocked($this->_style->getProtection()->getLocked());
			$style  |= self::_mapHidden($this->_style->getProtection()->getHidden()) << 1;
		}

		// Flags to indicate if attributes have been set.
		$atr_num     = ($this->_numberFormatIndex != 0)?1:0;
		$atr_fnt     = ($this->_fontIndex != 0)?1:0;
		$atr_alc     = ((int) $this->_style->getAlignment()->getWrapText())?1:0;
		$atr_bdr     = (self::_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle())   ||
						self::_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle())      ||
						self::_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle())     ||
						self::_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()))?1:0;
		$atr_pat     = (($this->_fg_color != 0x40) ||
						($this->_bg_color != 0x41) ||
						self::_mapFillType($this->_style->getFill()->getFillType()))?1:0;
		$atr_prot    = self::_mapLocked($this->_style->getProtection()->getLocked())
						| self::_mapHidden($this->_style->getProtection()->getHidden());

		// Zero the default border colour if the border has not been set.
		if (self::_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) == 0) {
			$this->_bottom_color = 0;
		}
		if (self::_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle())  == 0) {
			$this->_top_color = 0;
		}
		if (self::_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) == 0) {
			$this->_right_color = 0;
		}
		if (self::_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) == 0) {
			$this->_left_color = 0;
		}
		if (self::_mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) == 0) {
			$this->_diag_color = 0;
		}

		$record         = 0x00E0;              // Record identifier
		$length         = 0x0014;              // Number of bytes to follow

		$ifnt           = $this->_fontIndex;   // Index to FONT record
		$ifmt           = $this->_numberFormatIndex;  // Index to FORMAT record

		$align          = $this->_mapHAlign($this->_style->getAlignment()->getHorizontal());       // Alignment
		$align         |= (int) $this->_style->getAlignment()->getWrapText()     << 3;
		$align         |= self::_mapVAlign($this->_style->getAlignment()->getVertical())  << 4;
		$align         |= $this->_text_justlast << 7;

		$used_attrib    = $atr_num              << 2;
		$used_attrib   |= $atr_fnt              << 3;
		$used_attrib   |= $atr_alc              << 4;
		$used_attrib   |= $atr_bdr              << 5;
		$used_attrib   |= $atr_pat              << 6;
		$used_attrib   |= $atr_prot             << 7;

		$icv            = $this->_fg_color;      // fg and bg pattern colors
		$icv           |= $this->_bg_color      << 7;

		$border1        = self::_mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle());          // Border line style and color
		$border1       |= self::_mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle())         << 4;
		$border1       |= self::_mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle())           << 8;
		$border1       |= self::_mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle())        << 12;
		$border1       |= $this->_left_color    << 16;
		$border1       |= $this->_right_color   << 23;

		$diagonalDirection = $this->_style->getBorders()->getDiagonalDirection();
		$diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH
							|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN;
		$diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH
							|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP;
		$border1       |= $diag_tl_to_rb        << 30;
		$border1       |= $diag_tr_to_lb        << 31;

		$border2        = $this->_top_color;    // Border color
		$border2       |= $this->_bottom_color   << 7;
		$border2       |= $this->_diag_color     << 14;
		$border2       |= self::_mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle())           << 21;
		$border2       |= self::_mapFillType($this->_style->getFill()->getFillType())        << 26;

		$header      = pack("vv",       $record, $length);

		//BIFF8 options: identation, shrinkToFit and  text direction
		$biff8_options  = $this->_style->getAlignment()->getIndent();
		$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4;

		$data  = pack("vvvC", $ifnt, $ifmt, $style, $align);
		$data .= pack("CCC"
			, self::_mapTextRotation($this->_style->getAlignment()->getTextRotation())
			, $biff8_options
			, $used_attrib
			);
		$data .= pack("VVv", $border1, $border2, $icv);

		return($header . $data);
	}
772862
protected void CreateKeys(OffsetItem fdarrayRef,OffsetItem fdselectRef,OffsetItem charsetRef,OffsetItem charstringsRef)
	{
	    // create an FDArray key
        OutputList.addLast(fdarrayRef);
        OutputList.addLast(new UInt8Item((char)12));
        OutputList.addLast(new UInt8Item((char)36));
        // create an FDSelect key
        OutputList.addLast(fdselectRef);
        OutputList.addLast(new UInt8Item((char)12));
        OutputList.addLast(new UInt8Item((char)37));
        // create an charset key
        OutputList.addLast(charsetRef);
        OutputList.addLast(new UInt8Item((char)15));
        // create a CharStrings key
        OutputList.addLast(charstringsRef);
        OutputList.addLast(new UInt8Item((char)17));
	}
1139940
public void save(final KeyPair keyPair) throws IOException {
        LOGGER.info("Saving key pair");
        final PrivateKey privateKey = keyPair.getPrivate();
        final PublicKey publicKey = keyPair.getPublic();

        // Store Public Key
        final File publicKeyFile = getKeyPath(publicKey);
        publicKeyFile.getParentFile().mkdirs(); // make directories if they do not exist
        final X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
        try (OutputStream fos = Files.newOutputStream(publicKeyFile.toPath())) {
            fos.write(x509EncodedKeySpec.getEncoded());
        }

        // Store Private Key.
        final File privateKeyFile = getKeyPath(privateKey);
        privateKeyFile.getParentFile().mkdirs(); // make directories if they do not exist
        final PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
        try (OutputStream fos = Files.newOutputStream(privateKeyFile.toPath())) {
            fos.write(pkcs8EncodedKeySpec.getEncoded());
        }
    }
313507
public void writeDirect( byte[] b, int off, int len, int flags ) throws IOException {
        if( len <= 0 ) {
            return;
        }

        if( tmp == null ) {
            throw new IOException( "Bad file descriptor" );
        }
        ensureOpen();

        if( file.log.level >= 4 )
            file.log.println( "write: fid=" + file.fid + ",off=" + off + ",len=" + len );

        int w;
        do {
            w = len > writeSize ? writeSize : len;
            if( useNTSmbs ) {
                reqx.setParam( file.fid, fp, len - w, b, off, w );
if ((flags & 1) != 0) {
    reqx.setParam( file.fid, fp, len, b, off, w );
    reqx.writeMode = 0x8;
} else {
    reqx.writeMode = 0;
}
                file.send( reqx, rspx );
                fp += rspx.count;
                len -= rspx.count;
                off += rspx.count;
            } else {
                req.setParam( file.fid, fp, len - w, b, off, w );
                fp += rsp.count;
                len -= rsp.count;
                off += rsp.count;
                file.send( req, rsp );
            }
        } while( len > 0 );
    }
635631
public void addRdfDescription(XmpSchema s) throws IOException {
		writer.write("<rdf:Description rdf:about=\"");
		writer.write(about);
		writer.write("\" ");
		writer.write(s.getXmlns());
		writer.write(">");
		writer.write(s.toString());
		writer.write("</rdf:Description>\n");
	}