@Override public boolean download(String fileName, OutputStream outputStream) { return doExecute(Unchecked.function(client -> client.retrieveFile(fileName, outputStream))); }
dataAndExpected.add(new Tuple3<>(1, 1, 11)); dataAndExpected.add(new Tuple3<>(2, 2, 2042)); dataAndExpected.add(new Tuple3<>(3, 3, 2052)); dataAndExpected.add(new Tuple3<>(4, 4, 3078)); dataAndExpected.add(new Tuple3<>(5, 5, 3196)); dataAndExpected.add(new Tuple3<>(6, 6, 3202)); dataAndExpected.add(new Tuple3<>(7, 7, 6252)); dataAndExpected.add(new Tuple3<>(8, 8, 6321)); dataAndExpected.add(new Tuple3<>(9, 9, 6397)); dataAndExpected.add(new Tuple3<>(10, 10, 6476)); dataAndExpected.add(new Tuple3<>(11, 11, 6554)); dataAndExpected.add(new Tuple3<>(12, 12, null)); dataAndExpected.add(new Tuple3<>(13, 12, null)); dataAndExpected.forEach(Unchecked.consumer(data -> { Map<String, Object> result = handler.substringSearch(file, pattern, data.v1()); assertEquals(data.v3(), result.get("nextByteOffset")); assertEquals(data.v2().intValue(), ((List) result.get("matches")).size()); }));
/** * Map this stream to a windowed stream using a specific partition and order with frame. * <p> * <code><pre> * // (3, 2, 4, 4, 3) * Seq.of(1, 2, 4, 2, 3).window(i -> i % 2, naturalOrder(), -1, 1).map(Window::max) * </pre></code> */ default <U> Seq<Window<T>> window(Function<? super T, ? extends U> partitionBy, Comparator<? super T> orderBy, long lower, long upper) { return window(Window.of(partitionBy, orderBy, lower, upper)).map(t -> t.v1); }
/** * Returns a <code>Seq</code> over given <code>source</code>. * * Although such <code>Seq</code> is not thread-safe by itself, it interacts in a thread-safe way with its * parent <code>SeqBuffer</code>. As a result, each <code>Seq</code> returned by this method can be safely * used on a different thread. */ Seq<T> seq() { return Seq.seq(new BufferSpliterator()); }
@Override public String commonSuffix() { return partition.cacheIf(completePartition(), () -> "commonSuffix", () -> window().commonSuffix()); } }
/** * Inner join stream with itself. * <p> * <code><pre> * // (tuple(1, 1), tuple(2, 2)) * Seq.of(1, 2).innerSelfJoin((t, u) -> Objects.equals(t, u)) * </pre></code> */ default Seq<Tuple2<T, T>> innerSelfJoin(BiPredicate<? super T, ? super T> predicate) { SeqBuffer<T> buffer = SeqBuffer.of(this); return buffer.seq().innerJoin(buffer.seq(), predicate); }
/** * Map this stream to a windowed stream using a specific partition and the default order. * <p> * <code><pre> * // (1, 2, 2, 2, 1) * Seq.of(1, 2, 4, 2, 3).window(i -> i % 2).map(Window::min) * </pre></code> */ default <U> Seq<Window<T>> window(Function<? super T, ? extends U> partitionBy) { return window(Window.of(partitionBy)).map(t -> t.v1); }
@Override public boolean delete(String fileName) { return doExecute(Unchecked.function(client -> client.deleteFile(fileName))); }
List<File> files1 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("A" + idx) .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList()); List<File> files2 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("B" + idx) .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList()); List<File> files3 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("C" + idx) .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList()); File port1Dir = new MockDirectoryBuilder().setDirName("/workers-artifacts/topo1/port1") .setFiles(files1.toArray(new File[]{})).build();
@Override public void list(String path, Consumer<FTPFile> consumer) { doExecute(Unchecked.function(client -> { Arrays.stream(client.listFiles(path)).forEach(consumer); return null; })); } }
List<File> files1 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("A" + idx + ".log") .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList()); List<File> files2 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("B" + idx) .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList()); List<File> files3 = Seq.range(0, 10).map(idx -> new MockRemovableFileBuilder().setFileName("C" + idx) .setMtime(nowMillis + (100 * idx)).setLength(200).build()) .collect(toList());
@Override public boolean rename(String from, String to) { return doExecute(Unchecked.function(client -> client.rename(from, to))); }
@Override public boolean upload(String fileName, InputStream input) { return doExecute(Unchecked.function(client -> client.storeFile(fileName, input))); }
@Override public boolean upload(String fileName, String text) { return doExecute(Unchecked.function(client -> { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes())) { return client.storeFile(fileName, inputStream); } })); }
/** * Delete the oldest files in each overloaded worker log dir. */ @VisibleForTesting List<DeletionMeta> perWorkerDirCleanup(long size) { return workerLogs.getAllWorkerDirs().stream() .map(Unchecked.function(dir -> directoryCleaner.deleteOldestWhileTooLarge(Collections.singletonList(dir), size, true, null))) .collect(toList()); }
try { logFiles = Arrays.stream(topoDir.listFiles()) .flatMap(Unchecked.function(portDir -> directoryCleaner.getFilesForDir(portDir).stream())) .filter(File::isFile) .collect(toCollection(TreeSet::new));