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

org.cuberact.tools.bytes.ByteInputStream Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package org.cuberact.tools.bytes;

import java.io.IOException;
import java.io.InputStream;

public class ByteInputStream extends InputStream {

    private final InputStream stream;
    private boolean repeatLastByte = false;
    private int lastByte;

    public ByteInputStream(InputStream stream) {
        this.stream = stream;
    }

    @Override
    public int read() throws IOException {
        if (repeatLastByte) {
            repeatLastByte = false;
            return lastByte;
        }
        lastByte = stream.read();
        return lastByte;
    }

    public int available() throws IOException {
        int available = stream.available();
        if (repeatLastByte) available++;
        return available;
    }

    public void repeatLastByte() {
        repeatLastByte = true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy