PacketWriter.java 1.63 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xmp.core.serializer.impl;

import com.adobe.xmp.core.impl.Utils;
import com.adobe.xmp.core.serializer.SerializeOptions;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

class PacketWriter
extends OutputStreamWriter {
    private SerializeOptions options;

    public PacketWriter(OutputStream out, SerializeOptions options) throws UnsupportedEncodingException {
        super(out, options.getEncoding());
        this.options = options;
    }

    public void indent(int times) throws IOException {
        StringBuilder bldr = new StringBuilder();
        for (int i = this.options.getBaseIndent() + times; i > 0; --i) {
            bldr.append(this.options.getIndent());
        }
        this.write(bldr.toString());
    }

    public void newline() throws IOException {
        this.write(this.options.getNewline());
    }

    public void fillWithChar(int number, char c) throws IOException {
        while (number > 0) {
            this.write(c);
            --number;
        }
    }

    public void writeAttribute(String attrName, String attrValue) throws IOException {
        StringBuilder bldr = new StringBuilder();
        bldr.append(attrName);
        bldr.append("=\"");
        if (attrValue == null) {
            attrValue = "";
        }
        bldr.append(Utils.escapeXML(attrValue, true, true));
        bldr.append('\"');
        this.write(bldr.toString());
    }

    public void writeTagBody(String value) throws IOException {
        this.write(Utils.escapeXML(value, false, true));
    }
}