當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalFileSystem.open方法代碼示例

本文整理匯總了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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:TestFSInputChecker.java

示例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();    
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:TestFSInputChecker.java

示例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);
}
 
開發者ID:Nextzero,項目名稱:hadoop-2.6.0-cdh5.4.3,代碼行數:32,代碼來源:TaskLogsTruncater.java

示例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);
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:30,代碼來源:TestFSInputChecker.java

示例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);
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:30,代碼來源:TestFSInputChecker.java

示例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();
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:28,代碼來源:TestFSInputChecker.java


注:本文中的org.apache.hadoop.fs.LocalFileSystem.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。