/*
* 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
*
* 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.vfs2.provider.hdfs;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.vfs2.provider.AbstractRandomAccessContent;
import org.apache.commons.vfs2.util.RandomAccessMode;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
Provides random access to content in an HdfsFileObject. Currently this only supports read operations. All write operations throw an UnsupportedOperationException
. Since: 2.1
/**
* Provides random access to content in an HdfsFileObject. Currently this only supports read operations. All write
* operations throw an {@link UnsupportedOperationException}.
*
* @since 2.1
*/
public class HdfsRandomAccessContent extends AbstractRandomAccessContent {
private final FSDataInputStream fis;
private final FileSystem fs;
private final Path path;
Create random access content.
Params: - path – A Hadoop Path
- fs – A Hadoop FileSystem
Throws: - IOException – when the path cannot be processed.
/**
* Create random access content.
*
* @param path A Hadoop Path
* @param fs A Hadoop FileSystem
* @throws IOException when the path cannot be processed.
*/
public HdfsRandomAccessContent(final Path path, final FileSystem fs) throws IOException {
super(RandomAccessMode.READ);
this.fs = fs;
this.path = path;
this.fis = this.fs.open(this.path);
}
See Also: - close.close()
/**
* @see org.apache.commons.vfs2.RandomAccessContent#close()
*/
@Override
public void close() throws IOException {
this.fis.close();
}
See Also: - getFilePointer.getFilePointer()
/**
* @see org.apache.commons.vfs2.RandomAccessContent#getFilePointer()
*/
@Override
public long getFilePointer() throws IOException {
return this.fis.getPos();
}
See Also: - getInputStream.getInputStream()
/**
* @see org.apache.commons.vfs2.RandomAccessContent#getInputStream()
*/
@Override
public InputStream getInputStream() throws IOException {
return this.fis;
}
See Also: - length.length()
/**
* @see org.apache.commons.vfs2.RandomAccessContent#length()
*/
@Override
public long length() throws IOException {
return this.fs.getFileStatus(this.path).getLen();
}
See Also: - readBoolean.readBoolean()
/**
* @see java.io.DataInput#readBoolean()
*/
@Override
public boolean readBoolean() throws IOException {
return this.fis.readBoolean();
}
See Also: - readByte.readByte()
/**
* @see java.io.DataInput#readByte()
*/
@Override
public byte readByte() throws IOException {
return this.fis.readByte();
}
See Also: - readChar.readChar()
/**
* @see java.io.DataInput#readChar()
*/
@Override
public char readChar() throws IOException {
return this.fis.readChar();
}
See Also: - readDouble.readDouble()
/**
* @see java.io.DataInput#readDouble()
*/
@Override
public double readDouble() throws IOException {
return this.fis.readDouble();
}
See Also: - readFloat.readFloat()
/**
* @see java.io.DataInput#readFloat()
*/
@Override
public float readFloat() throws IOException {
return this.fis.readFloat();
}
See Also: - readFully.readFully(byte[])
/**
* @see java.io.DataInput#readFully(byte[])
*/
@Override
public void readFully(final byte[] b) throws IOException {
throw new UnsupportedOperationException();
}
See Also: - readFully.readFully(byte[], int, int)
/**
* @see java.io.DataInput#readFully(byte[], int, int)
*/
@Override
public void readFully(final byte[] b, final int off, final int len) throws IOException {
throw new UnsupportedOperationException();
}
See Also: - readInt.readInt()
/**
* @see java.io.DataInput#readInt()
*/
@Override
public int readInt() throws IOException {
return this.fis.readInt();
}
See Also: - readLine.readLine()
/**
* @see java.io.DataInput#readLine()
*/
@Override
@SuppressWarnings("deprecation")
public String readLine() throws IOException {
return this.fis.readLine();
}
See Also: - readLong.readLong()
/**
* @see java.io.DataInput#readLong()
*/
@Override
public long readLong() throws IOException {
return this.fis.readLong();
}
See Also: - readShort.readShort()
/**
* @see java.io.DataInput#readShort()
*/
@Override
public short readShort() throws IOException {
return this.fis.readShort();
}
See Also: - readUnsignedByte.readUnsignedByte()
/**
* @see java.io.DataInput#readUnsignedByte()
*/
@Override
public int readUnsignedByte() throws IOException {
return this.fis.readUnsignedByte();
}
See Also: - readUnsignedShort.readUnsignedShort()
/**
* @see java.io.DataInput#readUnsignedShort()
*/
@Override
public int readUnsignedShort() throws IOException {
return this.fis.readUnsignedShort();
}
See Also: - readUTF.readUTF()
/**
* @see java.io.DataInput#readUTF()
*/
@Override
public String readUTF() throws IOException {
return this.fis.readUTF();
}
See Also: - seek.seek(long)
/**
* @see org.apache.commons.vfs2.RandomAccessContent#seek(long)
*/
@Override
public void seek(final long pos) throws IOException {
this.fis.seek(pos);
}
See Also: - setLength.setLength(long)
/**
* @see org.apache.commons.vfs2.RandomAccessContent#setLength(long)
*/
@Override
public void setLength(final long newLength) throws IOException {
throw new UnsupportedOperationException();
}
See Also: - skipBytes.skipBytes(int)
/**
* @see java.io.DataInput#skipBytes(int)
*/
@Override
public int skipBytes(final int n) throws IOException {
throw new UnsupportedOperationException();
}
}