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

io.nosqlbench.nb.api.content.Content Maven / Gradle / Ivy

There is a newer version: 4.15.102
Show newest version
package io.nosqlbench.nb.api.content;

import java.io.*;
import java.net.URI;
import java.nio.CharBuffer;
import java.nio.file.FileSystem;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.spi.FileSystemProvider;
import java.util.function.Supplier;

/**
 * A generic content wrapper for anything that can be given to a NoSQLBench runtime
 * using a specific type of locator.
 *
 * @param 
 */
public interface Content extends Supplier, Comparable> {

    T getLocation();

    URI getURI();

    Path asPath();

    public default String asString() {
        return getCharBuffer().toString();
    }

    CharBuffer getCharBuffer();

    @Override
    default CharSequence get() {
        return getCharBuffer();
    }

    default int compareTo(Content other) {
        return getURI().compareTo(other.getURI());
    }

    default Reader getReader() {
        InputStream inputStream = getInputStream();
        return new InputStreamReader(inputStream);
    }

    default InputStream getInputStream() {
        try {
            Path path = asPath();
            FileSystem fileSystem = path.getFileSystem();
            FileSystemProvider provider = fileSystem.provider();
            InputStream stream = provider.newInputStream(path, StandardOpenOption.READ);
            return stream;
        } catch (IOException ignored) {
        }

        String stringdata = getCharBuffer().toString();
        return new ByteArrayInputStream(stringdata.getBytes());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy