@Test @Category(UnitTest.class) public void testReadSplitsVersion3() throws Exception { String version = "v3"; int count = 3; FileSplit.FileSplitInfo split1 = new FileSplit.FileSplitInfo(1, 2, "split1", 0); FileSplit.FileSplitInfo split2 = new FileSplit.FileSplitInfo(6, 4, "split2", 1); FileSplit.FileSplitInfo split3 = new FileSplit.FileSplitInfo(7, 9, "split3", 2); StringBuffer sb = new StringBuffer(); sb.append(version); sb.append("\n"); sb.append(count); sb.append("\n"); appendSplit(split1, sb); sb.append("\n"); appendSplit(split2, sb); sb.append("\n"); appendSplit(split3, sb); ByteArrayInputStream in = new ByteArrayInputStream(sb.toString().getBytes()); subject = new FileSplit(); subject.readSplits(in); SplitInfo[] splits = subject.getSplits(); Assert.assertEquals(2, splits.length); verifySplit(split1, splits, 0); verifySplit(split3, splits, 1); }
public void readSplits(InputStream stream) throws SplitException { try (Scanner reader = new Scanner(stream)) { String first = reader.nextLine(); if (first.equals(VERSION)) { readSplits(reader); } else { long split = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(first)).getLong(); if (split == VERSION_2) { throw new SplitException("Old version 2 splits file, you need to convert it to version 3, " + "this can be done by calling readSplits(path) instead of readSplits(stream)"); } else { throw new SplitException("Unrecognized splits"); } } } }
FileSplit extends Splits { public void readSplits(InputStream stream) throws SplitException { try (Scanner reader = new Scanner(stream)) { String first = reader.nextLine(); if (first.equals(VERSION)) { readSplits(reader); } else { long split = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(first)).getLong(); if (split == VERSION_2) { throw new SplitException("Old version 2 splits file, you need to convert it to version 3, " + "this can be done by calling readSplits(path) instead of readSplits(stream)"); } else { throw new SplitException("Unrecognized splits"); } } } } }
FileSplit extends Splits { public void readSplits(InputStream stream) throws SplitException { try (Scanner reader = new Scanner(stream)) { String first = reader.nextLine(); if (first.equals(VERSION)) { readSplits(reader); } else { long split = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(first)).getLong(); if (split == VERSION_2) { throw new SplitException("Old version 2 splits file, you need to convert it to version 3, " + "this can be done by calling readSplits(path) instead of readSplits(stream)"); } else { throw new SplitException("Unrecognized splits"); } } } }  }
FileSplit extends Splits { public void readSplits(InputStream stream) throws SplitException { try (Scanner reader = new Scanner(stream)) { String first = reader.nextLine(); if (first.equals(VERSION)) { readSplits(reader); } else { long split = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(first)).getLong(); if (split == VERSION_2) { throw new SplitException("Old version 2 splits file, you need to convert it to version 3, " + "this can be done by calling readSplits(path) instead of readSplits(stream)"); } else { throw new SplitException("Unrecognized splits"); } } } }  void generateSplits(FileSplitInfo[] splits); void generateSplits(long[] startIds, long[] endIds, String[] names); void generateSplits(Path parent, Configuration conf); @Override String findSplitFile(Path parent); @Override void generateSplits(SplitGenerator generator); void readSplits(InputStream stream); @SuppressWarnings("squid:S1166") // Exception caught and handled boolean isVersion2(Path splitsfile); void readSplits(Path parent); void writeSplits(OutputStream stream); void writeSplits(Path parent); @Override void readExternal(ObjectInput in); }
FileSplit extends Splits { public void readSplits(InputStream stream) throws SplitException { try (Scanner reader = new Scanner(stream)) { String first = reader.nextLine(); if (first.equals(VERSION)) { readSplits(reader); } else { long split = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(first)).getLong(); if (split == VERSION_2) { throw new SplitException("Old version 2 splits file, you need to convert it to version 3, " + "this can be done by calling readSplits(path) instead of readSplits(stream)"); } else { throw new SplitException("Unrecognized splits"); } } } }  void generateSplits(FileSplitInfo[] splits); void generateSplits(long[] startIds, long[] endIds, String[] names); void generateSplits(Path parent, Configuration conf); @Override String findSplitFile(Path parent); @Override void generateSplits(SplitGenerator generator); void readSplits(InputStream stream); @SuppressWarnings("squid:S1166") // Exception caught and handled boolean isVersion2(Path splitsfile); void readSplits(Path parent); void writeSplits(OutputStream stream); void writeSplits(Path parent); @Override void readExternal(ObjectInput in); static final String SPLIT_FILE; static final String OLD_SPLIT_FILE; }