@Test @Category(UnitTest.class) public void testReadSplitsByStreamNotVersion2() { ByteBuffer byteBuffer = ByteBuffer.allocate(8); byteBuffer.putLong(-2468); byte[] base64Bytes = org.apache.commons.codec.binary.Base64.encodeBase64(byteBuffer.array()); ByteArrayInputStream in = new ByteArrayInputStream(base64Bytes); subject = new FileSplit(); try { subject.readSplits(in); Assert.fail("Did not throw exception when reading non version 2 split file"); } catch (Splits.SplitException e) { e.printStackTrace(); } }
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; }