@Test public void testEmptyPath() throws Exception { EntropyInjectingFileSystem efs = new TestEntropyInjectingFs("test", "ignored"); Path path = new Path("hdfs: assertEquals(path, EntropyInjector.resolveEntropy(path, efs, true)); assertEquals(path, EntropyInjector.resolveEntropy(path, efs, false)); }
@VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } }
EntropyInjector { @VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } } }
EntropyInjector { @VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } } private  EntropyInjector(); }
EntropyInjector { @VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } } private  EntropyInjector(); static OutputStreamAndPath createEntropyAware(
			FileSystem fs,
			Path path,
			WriteMode writeMode); static Path removeEntropyMarkerIfPresent(FileSystem fs, Path path); }
EntropyInjector { @VisibleForTesting static Path resolveEntropy(Path path, EntropyInjectingFileSystem efs, boolean injectEntropy) throws IOException { final String entropyInjectionKey = efs.getEntropyInjectionKey(); if (entropyInjectionKey == null) { return path; } else { final URI originalUri = path.toUri(); final String checkpointPath = originalUri.getPath(); final int indexOfKey = checkpointPath.indexOf(entropyInjectionKey); if (indexOfKey == -1) { return path; } else { final StringBuilder buffer = new StringBuilder(checkpointPath.length()); buffer.append(checkpointPath, 0, indexOfKey); if (injectEntropy) { buffer.append(efs.generateEntropy()); } buffer.append(checkpointPath, indexOfKey + entropyInjectionKey.length(), checkpointPath.length()); final String rewrittenPath = buffer.toString(); try { return new Path(new URI( originalUri.getScheme(), originalUri.getAuthority(), rewrittenPath, originalUri.getQuery(), originalUri.getFragment()).normalize()); } catch (URISyntaxException e) { throw new IOException("URI format error while processing path for entropy injection", e); } } } } private  EntropyInjector(); static OutputStreamAndPath createEntropyAware(
			FileSystem fs,
			Path path,
			WriteMode writeMode); static Path removeEntropyMarkerIfPresent(FileSystem fs, Path path);  }