Example usage for org.apache.hadoop.io OutputBuffer OutputBuffer

List of usage examples for org.apache.hadoop.io OutputBuffer OutputBuffer

Introduction

In this page you can find the example usage for org.apache.hadoop.io OutputBuffer OutputBuffer.

Prototype

public OutputBuffer() 

Source Link

Document

Constructs a new empty buffer.

Usage

From source file:com.asakusafw.runtime.util.hadoop.ConfigurationDetecter.java

License:Apache License

/**
 * Read the path in the target file.//from  w  ww.j  a va 2 s.co m
 * @param path the file which has another path
 * @return the read path
 * @throws IOException if failed to read the path
 * @throws IllegalArgumentException if some parameters were {@code null}
 */
public static File read(File path) throws IOException {
    if (path == null) {
        throw new IllegalArgumentException("path must not be null"); //$NON-NLS-1$
    }
    String result;
    try (InputStream input = new FileInputStream(path); OutputBuffer ob = new OutputBuffer();) {
        byte[] buf = new byte[256];
        while (true) {
            int read = input.read(buf);
            if (read < 0) {
                break;
            }
            ob.write(buf, 0, read);
        }
        result = new String(ob.getData(), 0, ob.getLength(), ENCODING).trim();
    }
    File file = new File(result);
    return file;
}