Java Text File Write nio writeIfSet(final OutputStream outputStream, final String field, final String value)

Here you can find the source of writeIfSet(final OutputStream outputStream, final String field, final String value)

Description

write If Set

License

Apache License

Parameter

Parameter Description
field a parameter
value a parameter

Declaration

static final void writeIfSet(final OutputStream outputStream, final String field, final String value)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class Main {
    static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

    /**/*from  w w  w  .j a v  a  2  s.  c om*/
     * @param field
     * @param value
     */
    static final void writeIfSet(final OutputStream outputStream, final String field, final String value)
            throws IOException {
        if (null != value) {
            write(outputStream, field);
            write(outputStream, value);
            writeSeparator(outputStream);
        }
    }

    /**
     * @param outputStream
     * @param string
     */
    static final void write(final OutputStream outputStream, final String string) throws IOException {
        write(outputStream, string.getBytes(DEFAULT_CHARSET));
    }

    /**
     * @param outputStream
     * @param data
     */
    static final void write(final OutputStream outputStream, final byte[] data) throws IOException {
        outputStream.write(data);
    }

    /**
     * @param outputStream
     */
    static final void writeSeparator(final OutputStream outputStream) throws IOException {
        write(outputStream, "\r\n");
    }
}

Related

  1. writeDataFromList(String address, ArrayList toWrite)
  2. writeFileContent(File file, String content)
  3. writeFileContents(File file, String content)
  4. writeFileTxt(String fileName, String[] totalFile)
  5. writeHeader(DataOutput data, String header)
  6. writeLine(final CharBuffer line, final CharBuffer output)
  7. writeLines(Collection lines, File file)
  8. writeLines(File file, Iterable lines)
  9. writeLines(String fileName, String[] lines)