本文整理匯總了Java中org.apache.hadoop.fs.LocalFileSystem.open方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalFileSystem.open方法的具體用法?Java LocalFileSystem.open怎麽用?Java LocalFileSystem.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.fs.LocalFileSystem
的用法示例。
在下文中一共展示了LocalFileSystem.open方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testFileCorruption
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
private void testFileCorruption(LocalFileSystem fileSys) throws IOException {
// create a file and verify that checksum corruption results in
// a checksum exception on LocalFS
String dir = PathUtils.getTestDirName(getClass());
Path file = new Path(dir + "/corruption-test.dat");
Path crcFile = new Path(dir + "/.corruption-test.dat.crc");
writeFile(fileSys, file);
int fileLen = (int)fileSys.getFileStatus(file).getLen();
byte [] buf = new byte[fileLen];
InputStream in = fileSys.open(file);
IOUtils.readFully(in, buf, 0, buf.length);
in.close();
// check .crc corruption
checkFileCorruption(fileSys, file, crcFile);
fileSys.delete(file, true);
writeFile(fileSys, file);
// check data corrutpion
checkFileCorruption(fileSys, file, file);
fileSys.delete(file, true);
}
示例2: checkFileCorruption
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
private void checkFileCorruption(LocalFileSystem fileSys, Path file,
Path fileToCorrupt) throws IOException {
// corrupt the file
RandomAccessFile out =
new RandomAccessFile(new File(fileToCorrupt.toString()), "rw");
byte[] buf = new byte[(int)fileSys.getFileStatus(file).getLen()];
int corruptFileLen = (int)fileSys.getFileStatus(fileToCorrupt).getLen();
assertTrue(buf.length >= corruptFileLen);
rand.nextBytes(buf);
out.seek(corruptFileLen/2);
out.write(buf, 0, corruptFileLen/4);
out.close();
boolean gotException = false;
InputStream in = fileSys.open(file);
try {
IOUtils.readFully(in, buf, 0, buf.length);
} catch (ChecksumException e) {
gotException = true;
}
assertTrue(gotException);
in.close();
}
示例3: main
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
public static void main(String args[]) throws IOException {
isTruncaterJvm = true;
String taskRanFile = args[0];
Configuration conf = new Configuration();
//read the Task objects from the file
LocalFileSystem lfs = FileSystem.getLocal(conf);
FSDataInputStream din = lfs.open(new Path(taskRanFile));
int numTasksRan = din.readInt();
List<Task> taskAttemptsRan = new ArrayList<Task>();
for (int i = 0; i < numTasksRan; i++) {
Task t;
if (din.readBoolean()) {
t = new MapTask();
} else {
t = new ReduceTask();
}
t.readFields(din);
taskAttemptsRan.add(t);
}
Task firstTask = taskAttemptsRan.get(0);
TaskLogsTruncater trunc = new TaskLogsTruncater(conf);
trunc.truncateLogs(new JVMInfo(
TaskLog.getAttemptDir(firstTask.getTaskID(),
firstTask.isTaskCleanupTask()),
taskAttemptsRan));
System.exit(0);
}
示例4: testFileCorruption
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
private void testFileCorruption(LocalFileSystem fileSys) throws IOException {
// create a file and verify that checksum corruption results in
// a checksum exception on LocalFS
String dir = System.getProperty("test.build.data", ".");
Path file = new Path(dir + "/corruption-test.dat");
Path crcFile = new Path(dir + "/.corruption-test.dat.crc");
writeFile(fileSys, file);
int fileLen = (int)fileSys.getFileStatus(file).getLen();
byte [] buf = new byte[fileLen];
InputStream in = fileSys.open(file);
IOUtils.readFully(in, buf, 0, buf.length);
in.close();
// check .crc corruption
checkFileCorruption(fileSys, file, crcFile);
fileSys.delete(file, true);
writeFile(fileSys, file);
// check data corrutpion
checkFileCorruption(fileSys, file, file);
fileSys.delete(file, true);
}
示例5: testFileCorruption
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
private void testFileCorruption(LocalFileSystem fileSys) throws IOException {
// create a file and verify that checksum corruption results in
// a checksum exception on LocalFS
String dir = System.getProperty("test.build.data", ".");
Path file = new Path(dir + "/corruption-test.dat");
Path crcFile = new Path(dir + "/.corruption-test.dat.crc");
writeFile(fileSys, file);
int fileLen = (int) fileSys.getFileStatus(file).getLen();
byte[] buf = new byte[fileLen];
InputStream in = fileSys.open(file);
IOUtils.readFully(in, buf, 0, buf.length);
in.close();
// check .crc corruption
checkFileCorruption(fileSys, file, crcFile);
fileSys.delete(file, true);
writeFile(fileSys, file);
// check data corrutpion
checkFileCorruption(fileSys, file, file);
fileSys.delete(file, true);
}
示例6: checkFileCorruption
import org.apache.hadoop.fs.LocalFileSystem; //導入方法依賴的package包/類
private void checkFileCorruption(LocalFileSystem fileSys, Path file,
Path fileToCorrupt) throws IOException {
// corrupt the file
RandomAccessFile out =
new RandomAccessFile(new File(fileToCorrupt.toString()), "rw");
byte[] buf = new byte[(int) fileSys.getFileStatus(file).getLen()];
int corruptFileLen = (int) fileSys.getFileStatus(fileToCorrupt).getLen();
assertTrue(buf.length >= corruptFileLen);
rand.nextBytes(buf);
out.seek(corruptFileLen / 2);
out.write(buf, 0, corruptFileLen / 4);
out.close();
boolean gotException = false;
InputStream in = fileSys.open(file);
try {
IOUtils.readFully(in, buf, 0, buf.length);
} catch (ChecksumException e) {
gotException = true;
}
assertTrue(gotException);
in.close();
}