类org.apache.hadoop.util.LineReader源码实例Demo

下面列出了怎么用org.apache.hadoop.util.LineReader的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: TestKeyValueTextInputFormat.java
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();
    }
  }
}
 
源代码2 项目: hadoop   文件: TestKeyValueTextInputFormat.java
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();
    }
  }
}
 
源代码3 项目: hadoop   文件: TestTextInputFormat.java
/**
 * 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);
  }
}
 
源代码4 项目: hadoop   文件: TestMRKeyValueTextInputFormat.java
@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));
}
 
源代码5 项目: hadoop   文件: MultiFileWordCount.java
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;
}
 
源代码6 项目: big-c   文件: TestKeyValueTextInputFormat.java
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();
    }
  }
}
 
源代码7 项目: big-c   文件: TestKeyValueTextInputFormat.java
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();
    }
  }
}
 
源代码8 项目: big-c   文件: TestTextInputFormat.java
/**
 * 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);
  }
}
 
源代码9 项目: big-c   文件: TestMRKeyValueTextInputFormat.java
@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));
}
 
源代码10 项目: big-c   文件: MultiFileWordCount.java
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;
}
 
源代码11 项目: hbase   文件: CompactionTool.java
/**
 * 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<>();
  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;
}
 
源代码12 项目: RDFS   文件: TestKeyValueTextInputFormat.java
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));
}
 
源代码13 项目: RDFS   文件: TestTextInputFormat.java
/**
 * 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);
  }
}
 
源代码14 项目: RDFS   文件: HarIndex.java
/**
 * Constructor that reads the contents of the index file.
 * @param in An input stream to the index file.
 * @param max The size of the index file.
 * @throws IOException
 */
public HarIndex(InputStream in, long max) throws IOException {
  LineReader lineReader = new LineReader(in);
  Text text = new Text();
  long nread = 0;
  while (nread < max) {
    int n = lineReader.readLine(text);
    nread += n;
    String line = text.toString();
    try {
      parseLine(line);
    } catch (UnsupportedEncodingException e) {
      throw new IOException("UnsupportedEncodingException after reading " +
                            nread + "bytes");
    }
  }
}
 
源代码15 项目: RDFS   文件: HarFileSystem.java
public int getHarVersion() throws IOException {
  FSDataInputStream masterIn = fs.open(masterIndex);
  LineReader lmaster = new LineReader(masterIn, getConf());
  Text line = new Text();
  lmaster.readLine(line);
  try {
    masterIn.close();
  } catch(IOException e){
    //disregard it.
    // its a read.
  }
  String versionLine = line.toString();
  String[] arr = versionLine.split(" ");
  int version = Integer.parseInt(arr[0]);
  return version;
}
 
源代码16 项目: hadoop-gpu   文件: TestKeyValueTextInputFormat.java
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));
}
 
源代码17 项目: hadoop-gpu   文件: TestTextInputFormat.java
/**
 * 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);
  }
}
 
源代码18 项目: hadoop-gpu   文件: TestStreamedMerge.java
@Override
public void run() {
  try {
    in_ = connectInputStream();
    LineReader lineReader = new LineReader((InputStream)in_, conf_);
    Text line = new Text();
    while (lineReader.readLine(line) > 0) {
      buf_.append(line.toString());
      buf_.append('\n');
      line.clear();
    }
    lineReader.close();
    in_.close();
  } catch (IOException io) {
    throw new RuntimeException(io);
  }
}
 
源代码19 项目: hadoop-gpu   文件: HarFileSystem.java
public int getHarVersion() throws IOException { 
  FSDataInputStream masterIn = fs.open(masterIndex);
  LineReader lmaster = new LineReader(masterIn, getConf());
  Text line = new Text();
  lmaster.readLine(line);
  try {
    masterIn.close();
  } catch(IOException e){
    //disregard it.
    // its a read.
  }
  String versionLine = line.toString();
  String[] arr = versionLine.split(" ");
  int version = Integer.parseInt(arr[0]);
  return version;
}
 
源代码20 项目: hadoop   文件: TestConcatenatedCompressedInput.java
/**
 * 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();
  }
}
 
源代码21 项目: hadoop   文件: TestTextInputFormat.java
@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());
}
 
源代码22 项目: hadoop   文件: TestTextInputFormat.java
/**
 * 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);
  }
}
 
源代码23 项目: hadoop   文件: TestTextInputFormat.java
/**
 * 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();
  }
}
 
源代码24 项目: hadoop   文件: TestMRKeyValueTextInputFormat.java
@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());
}
 
源代码25 项目: hadoop   文件: Hadoop20JHParser.java
/**
 * Can this parser parse the input?
 * 
 * @param input
 * @return Whether this parser can parse the input.
 * @throws IOException
 * 
 *           We will deem a stream to be a good 0.20 job history stream if the
 *           first line is exactly "Meta VERSION=\"1\" ."
 */
public static boolean canParse(InputStream input) throws IOException {
  try {
    LineReader reader = new LineReader(input);

    Text buffer = new Text();

    return reader.readLine(buffer) != 0
        && buffer.toString().equals("Meta VERSION=\"1\" .");
  } catch (EOFException e) {
    return false;
  }
}
 
源代码26 项目: hadoop   文件: HadoopLogsAnalyzer.java
private LineReader maybeUncompressedPath(Path p)
    throws FileNotFoundException, IOException {
  CompressionCodecFactory codecs = new CompressionCodecFactory(getConf());
  inputCodec = codecs.getCodec(p);
  FileSystem fs = p.getFileSystem(getConf());
  FSDataInputStream fileIn = fs.open(p);

  if (inputCodec == null) {
    return new LineReader(fileIn, getConf());
  } else {
    inputDecompressor = CodecPool.getDecompressor(inputCodec);
    return new LineReader(inputCodec.createInputStream(fileIn,
        inputDecompressor), getConf());
  }
}
 
源代码27 项目: hadoop   文件: TextOutputReader.java
@Override
public void initialize(PipeMapRed pipeMapRed) throws IOException {
  super.initialize(pipeMapRed);
  clientIn = pipeMapRed.getClientInput();
  conf = pipeMapRed.getConfiguration();
  numKeyFields = pipeMapRed.getNumOfKeyFields();
  separator = pipeMapRed.getFieldSeparator();
  lineReader = new LineReader((InputStream)clientIn, conf);
  key = new Text();
  value = new Text();
  line = new Text();
}
 
源代码28 项目: hadoop   文件: KeyOnlyTextOutputReader.java
@Override
public void initialize(PipeMapRed pipeMapRed) throws IOException {
  super.initialize(pipeMapRed);
  clientIn = pipeMapRed.getClientInput();
  conf = pipeMapRed.getConfiguration();
  lineReader = new LineReader((InputStream)clientIn, conf);
  key = new Text();
  line = new Text();
}
 
源代码29 项目: big-c   文件: TestConcatenatedCompressedInput.java
/**
 * 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();
  }
}
 
源代码30 项目: big-c   文件: TestTextInputFormat.java
@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());
}
 
 类所在包
 类方法
 同包方法