@Test public void parseFragmentMetadata() throws Exception { RequestContext metaData = mock(RequestContext.class); ByteArrayOutputStream bas = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bas); os.writeLong(10); os.writeLong(100); os.writeObject(new String[]{"hostname"}); os.close(); when(metaData.getFragmentMetadata()).thenReturn(bas.toByteArray()); FragmentMetadata fragmentMetadata = Utilities.parseFragmentMetadata(metaData); assertEquals(10, fragmentMetadata.getStart()); assertEquals(100, fragmentMetadata.getEnd()); assertArrayEquals(new String[]{"hostname"}, fragmentMetadata.getHosts()); }
public static FragmentMetadata parseFragmentMetadata(RequestContext context) { if (context.getFragmentMetadata() == null) { return new FragmentMetadata(0, 0, HOSTS); } try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(context.getFragmentMetadata()))) { long start = objectStream.readLong(); long end = objectStream.readLong(); String[] hosts = (String[]) objectStream.readObject(); if (LOG.isDebugEnabled()) { LOG.debug("Parsed split: path={} start={} end={} hosts={}", context.getDataSource(), start, end, ArrayUtils.toString(hosts)); } return new FragmentMetadata(start, end, hosts); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException("Exception while reading expected fragment metadata", e); } }
Utilities { public static FragmentMetadata parseFragmentMetadata(RequestContext context) { if (context.getFragmentMetadata() == null) { return new FragmentMetadata(0, 0, HOSTS); } try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(context.getFragmentMetadata()))) { long start = objectStream.readLong(); long end = objectStream.readLong(); String[] hosts = (String[]) objectStream.readObject(); if (LOG.isDebugEnabled()) { LOG.debug("Parsed split: path={} start={} end={} hosts={}", context.getDataSource(), start, end, ArrayUtils.toString(hosts)); } return new FragmentMetadata(start, end, hosts); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException("Exception while reading expected fragment metadata", e); } } }
Utilities { public static FragmentMetadata parseFragmentMetadata(RequestContext context) { if (context.getFragmentMetadata() == null) { return new FragmentMetadata(0, 0, HOSTS); } try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(context.getFragmentMetadata()))) { long start = objectStream.readLong(); long end = objectStream.readLong(); String[] hosts = (String[]) objectStream.readObject(); if (LOG.isDebugEnabled()) { LOG.debug("Parsed split: path={} start={} end={} hosts={}", context.getDataSource(), start, end, ArrayUtils.toString(hosts)); } return new FragmentMetadata(start, end, hosts); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException("Exception while reading expected fragment metadata", e); } }  }
Utilities { public static FragmentMetadata parseFragmentMetadata(RequestContext context) { if (context.getFragmentMetadata() == null) { return new FragmentMetadata(0, 0, HOSTS); } try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(context.getFragmentMetadata()))) { long start = objectStream.readLong(); long end = objectStream.readLong(); String[] hosts = (String[]) objectStream.readObject(); if (LOG.isDebugEnabled()) { LOG.debug("Parsed split: path={} start={} end={} hosts={}", context.getDataSource(), start, end, ArrayUtils.toString(hosts)); } return new FragmentMetadata(start, end, hosts); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException("Exception while reading expected fragment metadata", e); } }  static byte[] parseBase64(String encoded, String paramName); static boolean isValidDirectoryName(String name); static boolean isValidRestrictedDirectoryName(String name); static Object createAnyInstance(Class<?> confClass,
                                           String className, RequestContext metaData); static Object createAnyInstance(String className); static void byteArrayToOctalString(byte[] bytes, StringBuilder sb); static String maskNonPrintables(String input); static FragmentMetadata parseFragmentMetadata(RequestContext context); static boolean aggregateOptimizationsSupported(RequestContext requestContext); static boolean implementsInterface(String className, Class<?> iface); static boolean isFragmenterCacheEnabled(); static String absoluteDataPath(String dataSource); static boolean isSecurityEnabled(Configuration configuration); static String rightTrimWhiteSpace(String s); static String getHost(String uri); }
Utilities { public static FragmentMetadata parseFragmentMetadata(RequestContext context) { if (context.getFragmentMetadata() == null) { return new FragmentMetadata(0, 0, HOSTS); } try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(context.getFragmentMetadata()))) { long start = objectStream.readLong(); long end = objectStream.readLong(); String[] hosts = (String[]) objectStream.readObject(); if (LOG.isDebugEnabled()) { LOG.debug("Parsed split: path={} start={} end={} hosts={}", context.getDataSource(), start, end, ArrayUtils.toString(hosts)); } return new FragmentMetadata(start, end, hosts); } catch (IOException | ClassNotFoundException e) { throw new RuntimeException("Exception while reading expected fragment metadata", e); } }  static byte[] parseBase64(String encoded, String paramName); static boolean isValidDirectoryName(String name); static boolean isValidRestrictedDirectoryName(String name); static Object createAnyInstance(Class<?> confClass,
                                           String className, RequestContext metaData); static Object createAnyInstance(String className); static void byteArrayToOctalString(byte[] bytes, StringBuilder sb); static String maskNonPrintables(String input); static FragmentMetadata parseFragmentMetadata(RequestContext context); static boolean aggregateOptimizationsSupported(RequestContext requestContext); static boolean implementsInterface(String className, Class<?> iface); static boolean isFragmenterCacheEnabled(); static String absoluteDataPath(String dataSource); static boolean isSecurityEnabled(Configuration configuration); static String rightTrimWhiteSpace(String s); static String getHost(String uri); static final Pattern SCHEME_PATTERN; static final Pattern NON_HOSTNAME_CHARACTERS; }