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


Java LineReader.readLine方法代碼示例

本文整理匯總了Java中org.apache.hadoop.util.LineReader.readLine方法的典型用法代碼示例。如果您正苦於以下問題:Java LineReader.readLine方法的具體用法?Java LineReader.readLine怎麽用?Java LineReader.readLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.util.LineReader的用法示例。


在下文中一共展示了LineReader.readLine方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testUTF8

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
public void testUTF8() throws Exception {
  LineReader in = null;

  try {
    in = makeStream("abcd\u20acbdcd\u20ac");
    Text line = new Text();
    in.readLine(line);
    assertEquals("readLine changed utf8 characters",
                 "abcd\u20acbdcd\u20ac", line.toString());
    in = makeStream("abc\u200axyz");
    in.readLine(line);
    assertEquals("split on fake newline", "abc\u200axyz", line.toString());
  } finally {
    if (in != null) {
      in.close();
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestKeyValueTextInputFormat.java

示例2: testNewLines

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
public void testNewLines() throws Exception {
  LineReader in = null;
  try {
    in = makeStream("a\nbb\n\nccc\rdddd\r\neeeee");
    Text out = new Text();
    in.readLine(out);
    assertEquals("line1 length", 1, out.getLength());
    in.readLine(out);
    assertEquals("line2 length", 2, out.getLength());
    in.readLine(out);
    assertEquals("line3 length", 0, out.getLength());
    in.readLine(out);
    assertEquals("line4 length", 3, out.getLength());
    in.readLine(out);
    assertEquals("line5 length", 4, out.getLength());
    in.readLine(out);
    assertEquals("line5 length", 5, out.getLength());
    assertEquals("end of file", 0, in.readLine(out));
  } finally {
    if (in != null) {
      in.close();
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestKeyValueTextInputFormat.java

示例3: testMaxLineLength

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Test readLine for correct interpretation of maxLineLength
 * (returned string should be clipped at maxLineLength, and the
 * remaining bytes on the same line should be thrown out).
 * Also check that returned value matches the string length.
 * Varies buffer size to stress test.
 *
 * @throws Exception
 */
@Test (timeout=5000)
public void testMaxLineLength() throws Exception {
  final String STR = "a\nbb\n\nccc\rdddd\r\neeeee";
  final int STRLENBYTES = STR.getBytes().length;
  Text out = new Text();
  for (int bufsz = 1; bufsz < STRLENBYTES+1; ++bufsz) {
    LineReader in = makeStream(STR, bufsz);
    int c = 0;
    c += in.readLine(out, 1);
    assertEquals("line1 length, bufsz: "+bufsz, 1, out.getLength());
    c += in.readLine(out, 1);
    assertEquals("line2 length, bufsz: "+bufsz, 1, out.getLength());
    c += in.readLine(out, 1);
    assertEquals("line3 length, bufsz: "+bufsz, 0, out.getLength());
    c += in.readLine(out, 3);
    assertEquals("line4 length, bufsz: "+bufsz, 3, out.getLength());
    c += in.readLine(out, 10);
    assertEquals("line5 length, bufsz: "+bufsz, 4, out.getLength());
    c += in.readLine(out, 8);
    assertEquals("line5 length, bufsz: "+bufsz, 5, out.getLength());
    assertEquals("end of file, bufsz: " +bufsz, 0, in.readLine(out));
    assertEquals("total bytes, bufsz: "+bufsz, c, STRLENBYTES);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:34,代碼來源:TestTextInputFormat.java

示例4: testNewLines

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
@Test
public void testNewLines() throws Exception {
  LineReader in = makeStream("a\nbb\n\nccc\rdddd\r\neeeee");
  Text out = new Text();
  in.readLine(out);
  assertEquals("line1 length", 1, out.getLength());
  in.readLine(out);
  assertEquals("line2 length", 2, out.getLength());
  in.readLine(out);
  assertEquals("line3 length", 0, out.getLength());
  in.readLine(out);
  assertEquals("line4 length", 3, out.getLength());
  in.readLine(out);
  assertEquals("line5 length", 4, out.getLength());
  in.readLine(out);
  assertEquals("line5 length", 5, out.getLength());
  assertEquals("end of file", 0, in.readLine(out));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestMRKeyValueTextInputFormat.java

示例5: CombineFileLineRecordReader

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
public CombineFileLineRecordReader(CombineFileSplit split,
    TaskAttemptContext context, Integer index) throws IOException {
  
  this.path = split.getPath(index);
  fs = this.path.getFileSystem(context.getConfiguration());
  this.startOffset = split.getOffset(index);
  this.end = startOffset + split.getLength(index);
  boolean skipFirstLine = false;
  
  //open the file
  fileIn = fs.open(path);
  if (startOffset != 0) {
    skipFirstLine = true;
    --startOffset;
    fileIn.seek(startOffset);
  }
  reader = new LineReader(fileIn);
  if (skipFirstLine) {  // skip first line and re-establish "startOffset".
    startOffset += reader.readLine(new Text(), 0,
                (int)Math.min((long)Integer.MAX_VALUE, end - startOffset));
  }
  this.pos = startOffset;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:MultiFileWordCount.java

示例6: getSplits

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Returns a split for each store files directory using the block location
 * of each file as locality reference.
 */
@Override
public List<InputSplit> getSplits(JobContext job) throws IOException {
  List<InputSplit> splits = new ArrayList<InputSplit>();
  List<FileStatus> files = listStatus(job);

  Text key = new Text();
  for (FileStatus file: files) {
    Path path = file.getPath();
    FileSystem fs = path.getFileSystem(job.getConfiguration());
    LineReader reader = new LineReader(fs.open(path));
    long pos = 0;
    int n;
    try {
      while ((n = reader.readLine(key)) > 0) {
        String[] hosts = getStoreDirHosts(fs, path);
        splits.add(new FileSplit(path, pos, n, hosts));
        pos += n;
      }
    } finally {
      reader.close();
    }
  }

  return splits;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:30,代碼來源:CompactionTool.java

示例7: distributeCache

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
public static boolean distributeCache(String chrList, Job job, String cacheName)
		throws IOException, URISyntaxException {
	job.addCacheFile(new URI(chrList + "#" + cacheName));

	Configuration conf = job.getConfiguration();
	Path refPath = new Path(chrList);
	FileSystem fs = refPath.getFileSystem(conf);
	FSDataInputStream refin = fs.open(refPath);
	LineReader in = new LineReader(refin);
	Text line = new Text();

	String chrFile = "";
	String[] chrs = new String[3];
	while ((in.readLine(line)) != 0) {
		chrFile = line.toString();
		chrs = chrFile.split("\t");
		File fileTest = new File(chrs[1]);
		if (fileTest.isFile()) {
			chrs[1] = "file://" + chrs[1];
		}
		job.addCacheFile(new URI(chrs[1] + "#" + chrs[0]));
	}
	in.close();
	refin.close();
	return true;
}
 
開發者ID:BGI-flexlab,項目名稱:SOAPgaea,代碼行數:27,代碼來源:WholeGenomeShare.java

示例8: writeDocnoMappingData

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Creates a mappings file from the contents of a flat text file containing docid to docno
 * mappings. This method is used by {@link WikipediaDocnoMappingBuilder} internally.
 *
 * @param inputFile flat text file containing docid to docno mappings
 * @param outputFile output mappings file
 * @throws IOException
 */
static public void writeDocnoMappingData(FileSystem fs, String inputFile, int n, String outputFile) throws IOException {
	LOG.info("Writing " + n + " docids to " + outputFile);
	LineReader reader = new LineReader(fs.open(new Path(inputFile)));

	int cnt = 0;
	Text line = new Text();

	FSDataOutputStream out = fs.create(new Path(outputFile), true);
	out.writeInt(n);
	for (int i = 0; i < n; i++) {
		reader.readLine(line);
		String[] arr = line.toString().split("\\t");
		out.writeInt(Integer.parseInt(arr[0]));
		cnt++;
		if (cnt % 100000 == 0) {
			LOG.info(cnt + " articles");
		}
	}
	out.close();
	reader.close();
	LOG.info("Done!");
}
 
開發者ID:yahoo,項目名稱:FEL,代碼行數:31,代碼來源:WikipediaDocnoMapping.java

示例9: testUTF8

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
@Test
public void testUTF8() throws Exception {
  LineReader in = null;

  try {
    in = makeStream("abcd\u20acbdcd\u20ac");
    Text line = new Text();
    in.readLine(line);
    assertEquals("readLine changed utf8 characters",
                 "abcd\u20acbdcd\u20ac", line.toString());
    in = makeStream("abc\u200axyz");
    in.readLine(line);
    assertEquals("split on fake newline", "abc\u200axyz", line.toString());
  } finally {
    if (in != null) {
      in.close();
    }
  }
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:20,代碼來源:TestKeyValueTextInputFormat.java

示例10: testNewLines

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
public void testNewLines() throws Exception {
  LineReader in = makeStream("a\nbb\n\nccc\rdddd\r\neeeee");
  Text out = new Text();
  in.readLine(out);
  assertEquals("line1 length", 1, out.getLength());
  in.readLine(out);
  assertEquals("line2 length", 2, out.getLength());
  in.readLine(out);
  assertEquals("line3 length", 0, out.getLength());
  in.readLine(out);
  assertEquals("line4 length", 3, out.getLength());
  in.readLine(out);
  assertEquals("line5 length", 4, out.getLength());
  in.readLine(out);
  assertEquals("line5 length", 5, out.getLength());
  assertEquals("end of file", 0, in.readLine(out));
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:18,代碼來源:TestKeyValueTextInputFormat.java

示例11: testMaxLineLength

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Test readLine for correct interpretation of maxLineLength
 * (returned string should be clipped at maxLineLength, and the
 * remaining bytes on the same line should be thrown out).
 * Also check that returned value matches the string length.
 * Varies buffer size to stress test.
 *
 * @throws Exception
 */
public void testMaxLineLength() throws Exception {
  final String STR = "a\nbb\n\nccc\rdddd\r\neeeee";
  final int STRLENBYTES = STR.getBytes().length;
  Text out = new Text();
  for (int bufsz = 1; bufsz < STRLENBYTES+1; ++bufsz) {
    LineReader in = makeStream(STR, bufsz);
    int c = 0;
    c += in.readLine(out, 1);
    assertEquals("line1 length, bufsz: "+bufsz, 1, out.getLength());
    c += in.readLine(out, 1);
    assertEquals("line2 length, bufsz: "+bufsz, 1, out.getLength());
    c += in.readLine(out, 1);
    assertEquals("line3 length, bufsz: "+bufsz, 0, out.getLength());
    c += in.readLine(out, 3);
    assertEquals("line4 length, bufsz: "+bufsz, 3, out.getLength());
    c += in.readLine(out, 10);
    assertEquals("line5 length, bufsz: "+bufsz, 4, out.getLength());
    c += in.readLine(out, 8);
    assertEquals("line5 length, bufsz: "+bufsz, 5, out.getLength());
    assertEquals("end of file, bufsz: " +bufsz, 0, in.readLine(out));
    assertEquals("total bytes, bufsz: "+bufsz, c, STRLENBYTES);
  }
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:33,代碼來源:TestTextInputFormat.java

示例12: main

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Parse the command line arguments into lines and display the result.
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
  for(String arg: args) {
    System.out.println("Working on " + arg);
    LineReader reader = makeStream(unquote(arg));
    Text line = new Text();
    int size = reader.readLine(line);
    while (size > 0) {
      System.out.println("Got: " + line.toString());
      size = reader.readLine(line);
    }
    reader.close();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestConcatenatedCompressedInput.java

示例13: testUTF8

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
@Test (timeout=5000)
public void testUTF8() throws Exception {
  LineReader in = makeStream("abcd\u20acbdcd\u20ac");
  Text line = new Text();
  in.readLine(line);
  assertEquals("readLine changed utf8 characters", 
               "abcd\u20acbdcd\u20ac", line.toString());
  in = makeStream("abc\u200axyz");
  in.readLine(line);
  assertEquals("split on fake newline", "abc\u200axyz", line.toString());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:TestTextInputFormat.java

示例14: testNewLines

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
/**
 * Test readLine for various kinds of line termination sequneces.
 * Varies buffer size to stress test.  Also check that returned
 * value matches the string length.
 *
 * @throws Exception
 */
@Test (timeout=5000)
public void testNewLines() throws Exception {
  final String STR = "a\nbb\n\nccc\rdddd\r\r\r\n\r\neeeee";
  final int STRLENBYTES = STR.getBytes().length;
  Text out = new Text();
  for (int bufsz = 1; bufsz < STRLENBYTES+1; ++bufsz) {
    LineReader in = makeStream(STR, bufsz);
    int c = 0;
    c += in.readLine(out); //"a"\n
    assertEquals("line1 length, bufsz:"+bufsz, 1, out.getLength());
    c += in.readLine(out); //"bb"\n
    assertEquals("line2 length, bufsz:"+bufsz, 2, out.getLength());
    c += in.readLine(out); //""\n
    assertEquals("line3 length, bufsz:"+bufsz, 0, out.getLength());
    c += in.readLine(out); //"ccc"\r
    assertEquals("line4 length, bufsz:"+bufsz, 3, out.getLength());
    c += in.readLine(out); //dddd\r
    assertEquals("line5 length, bufsz:"+bufsz, 4, out.getLength());
    c += in.readLine(out); //""\r
    assertEquals("line6 length, bufsz:"+bufsz, 0, out.getLength());
    c += in.readLine(out); //""\r\n
    assertEquals("line7 length, bufsz:"+bufsz, 0, out.getLength());
    c += in.readLine(out); //""\r\n
    assertEquals("line8 length, bufsz:"+bufsz, 0, out.getLength());
    c += in.readLine(out); //"eeeee"EOF
    assertEquals("line9 length, bufsz:"+bufsz, 5, out.getLength());
    assertEquals("end of file, bufsz: "+bufsz, 0, in.readLine(out));
    assertEquals("total bytes, bufsz: "+bufsz, c, STRLENBYTES);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:38,代碼來源:TestTextInputFormat.java

示例15: testUTF8

import org.apache.hadoop.util.LineReader; //導入方法依賴的package包/類
@Test
public void testUTF8() throws Exception {
  LineReader in = makeStream("abcd\u20acbdcd\u20ac");
  Text line = new Text();
  in.readLine(line);
  assertEquals("readLine changed utf8 characters", 
               "abcd\u20acbdcd\u20ac", line.toString());
  in = makeStream("abc\u200axyz");
  in.readLine(line);
  assertEquals("split on fake newline", "abc\u200axyz", line.toString());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:TestMRKeyValueTextInputFormat.java


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