All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nls.io.LimitedByteArrayOutputStream Maven / Gradle / Ivy

There is a newer version: 1.0.14
Show newest version
package com.nls.io;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class LimitedByteArrayOutputStream extends OutputStream {
    private final ByteArrayOutputStream buffer;
    private int limit;

    public LimitedByteArrayOutputStream(int limit) {
        this.buffer = new ByteArrayOutputStream(limit);
        this.limit = limit;
    }

    @Override
    public void write(int b) throws IOException {
        if (buffer.size() < limit) {
            buffer.write(b);
        }
    }

    @Override
    public String toString() {
        return buffer.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy