Android Open Source - magdaa-library String Builder Writer






From Project

Back to project page magdaa-library.

License

The source code is released under:

GNU General Public License

If you think the Android project magdaa-library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * /*from   www.j  a va 2s  .  c o m*/
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io.output;

import java.io.Serializable;
import java.io.Writer;

/**
 * {@link Writer} implementation that outputs to a {@link StringBuilder}.
 * <p>
 * <strong>NOTE:</strong> This implementation, as an alternative to
 * <code>java.io.StringWriter</code>, provides an <i>un-synchronized</i>
 * (i.e. for use in a single thread) implementation for better performance.
 * For safe usage with multiple {@link Thread}s then
 * <code>java.io.StringWriter</code> should be used.
 *
 * @version $Id: StringBuilderWriter.java 1304052 2012-03-22 20:55:29Z ggregory $
 * @since 2.0
 */
@SuppressWarnings("serial")
public class StringBuilderWriter extends Writer implements Serializable {

    private final StringBuilder builder;

    /**
     * Construct a new {@link StringBuilder} instance with default capacity.
     */
    public StringBuilderWriter() {
        this.builder = new StringBuilder();
    }

    /**
     * Construct a new {@link StringBuilder} instance with the specified capacity.
     *
     * @param capacity The initial capacity of the underlying {@link StringBuilder}
     */
    public StringBuilderWriter(int capacity) {
        this.builder = new StringBuilder(capacity);
    }

    /**
     * Construct a new instance with the specified {@link StringBuilder}.
     *
     * @param builder The String builder
     */
    public StringBuilderWriter(StringBuilder builder) {
        this.builder = builder != null ? builder : new StringBuilder();
    }

    /**
     * Append a single character to this Writer.
     *
     * @param value The character to append
     * @return This writer instance
     */
    @Override
    public Writer append(char value) {
        builder.append(value);
        return this;
    }

    /**
     * Append a character sequence to this Writer.
     *
     * @param value The character to append
     * @return This writer instance
     */
    @Override
    public Writer append(CharSequence value) {
        builder.append(value);
        return this;
    }

    /**
     * Append a portion of a character sequence to the {@link StringBuilder}.
     *
     * @param value The character to append
     * @param start The index of the first character
     * @param end The index of the last character + 1
     * @return This writer instance
     */
    @Override
    public Writer append(CharSequence value, int start, int end) {
        builder.append(value, start, end);
        return this;
    }

    /**
     * Closing this writer has no effect. 
     */
    @Override
    public void close() {
    }

    /**
     * Flushing this writer has no effect. 
     */
    @Override
    public void flush() {
    }


    /**
     * Write a String to the {@link StringBuilder}.
     * 
     * @param value The value to write
     */
    @Override
    public void write(String value) {
        if (value != null) {
            builder.append(value);
        }
    }

    /**
     * Write a portion of a character array to the {@link StringBuilder}.
     *
     * @param value The value to write
     * @param offset The index of the first character
     * @param length The number of characters to write
     */
    @Override
    public void write(char[] value, int offset, int length) {
        if (value != null) {
            builder.append(value, offset, length);
        }
    }

    /**
     * Return the underlying builder.
     *
     * @return The underlying builder
     */
    public StringBuilder getBuilder() {
        return builder;
    }

    /**
     * Returns {@link StringBuilder#toString()}.
     *
     * @return The contents of the String builder.
     */
    @Override
    public String toString() {
        return builder.toString();
    }
}




Java Source Code List

org.apache.commons.io.Charsets.java
org.apache.commons.io.FileExistsException.java
org.apache.commons.io.FileUtils.java
org.apache.commons.io.FilenameUtils.java
org.apache.commons.io.IOCase.java
org.apache.commons.io.IOUtils.java
org.apache.commons.io.LineIterator.java
org.apache.commons.io.filefilter.AbstractFileFilter.java
org.apache.commons.io.filefilter.AgeFileFilter.java
org.apache.commons.io.filefilter.AndFileFilter.java
org.apache.commons.io.filefilter.ConditionalFileFilter.java
org.apache.commons.io.filefilter.DelegateFileFilter.java
org.apache.commons.io.filefilter.DirectoryFileFilter.java
org.apache.commons.io.filefilter.FalseFileFilter.java
org.apache.commons.io.filefilter.FileFileFilter.java
org.apache.commons.io.filefilter.FileFilterUtils.java
org.apache.commons.io.filefilter.IOFileFilter.java
org.apache.commons.io.filefilter.MagicNumberFileFilter.java
org.apache.commons.io.filefilter.NameFileFilter.java
org.apache.commons.io.filefilter.NotFileFilter.java
org.apache.commons.io.filefilter.OrFileFilter.java
org.apache.commons.io.filefilter.PrefixFileFilter.java
org.apache.commons.io.filefilter.SizeFileFilter.java
org.apache.commons.io.filefilter.SuffixFileFilter.java
org.apache.commons.io.filefilter.TrueFileFilter.java
org.apache.commons.io.input.ClosedInputStream.java
org.apache.commons.io.output.ByteArrayOutputStream.java
org.apache.commons.io.output.NullOutputStream.java
org.apache.commons.io.output.StringBuilderWriter.java
org.magdaaproject.utils.DeviceUtils.java
org.magdaaproject.utils.FileUtils.java
org.magdaaproject.utils.GeoCoordUtils.java
org.magdaaproject.utils.OpenDataKitUtils.java
org.magdaaproject.utils.SensorUtilsException.java
org.magdaaproject.utils.SensorUtils.java
org.magdaaproject.utils.TimeUtils.java
org.magdaaproject.utils.UnitConversionUtils.java
org.magdaaproject.utils.readings.ReadingsList.java
org.magdaaproject.utils.readings.SensorReading.java
org.magdaaproject.utils.readings.TempHumidityReading.java
org.magdaaproject.utils.readings.WeatherReading.java
org.magdaaproject.utils.serval.RhizomeUtils.java
org.magdaaproject.utils.serval.ServalStatusReceiver.java
org.magdaaproject.utils.serval.ServalUtils.java
org.magdaaproject.utils.xforms.XFormsException.java
org.magdaaproject.utils.xforms.XFormsUtils.java
org.zeroturnaround.zip.ByteSource.java
org.zeroturnaround.zip.FileSource.java
org.zeroturnaround.zip.FileUtil.java
org.zeroturnaround.zip.IdentityNameMapper.java
org.zeroturnaround.zip.NameMapper.java
org.zeroturnaround.zip.ZipBreakException.java
org.zeroturnaround.zip.ZipEntryCallback.java
org.zeroturnaround.zip.ZipEntrySource.java
org.zeroturnaround.zip.ZipException.java
org.zeroturnaround.zip.ZipInfoCallback.java
org.zeroturnaround.zip.ZipUtil.java
org.zeroturnaround.zip.transform.ByteArrayZipEntryTransformer.java
org.zeroturnaround.zip.transform.FileZipEntryTransformer.java
org.zeroturnaround.zip.transform.StreamZipEntryTransformer.java
org.zeroturnaround.zip.transform.StringZipEntryTransformer.java
org.zeroturnaround.zip.transform.ZipEntrySourceZipEntryTransformer.java
org.zeroturnaround.zip.transform.ZipEntryTransformerEntry.java
org.zeroturnaround.zip.transform.ZipEntryTransformer.java