/** * Convenience method to copy the content of the file in this part to the * given destination file. If the destination file already exists, it will * be truncated first. * <p>The default implementation delegates to {@link #transferTo(Path)}. * @param dest the target file * @return completion {@code Mono} with the result of the file transfer, * possibly {@link IllegalStateException} if the part isn't a file * @see #transferTo(Path) */ default Mono<Void> transferTo(File dest) { return transferTo(dest.toPath()); }
/** * Convenience method to copy the content of the file in this part to the * given destination file. If the destination file already exists, it will * be truncated first. * <p>The default implementation delegates to {@link #transferTo(Path)}. * @param dest the target file * @return completion {@code Mono} with the result of the file transfer, * possibly {@link IllegalStateException} if the part isn't a file * @see #transferTo(Path) */ default Mono<Void> transferTo(File dest) { return transferTo(dest.toPath()); }
@Test // SPR-16545 public void transferTo() { ServerHttpRequest request = generateMultipartRequest(); ResolvableType elementType = forClassWithGenerics(MultiValueMap.class, String.class, Part.class); MultiValueMap<String, Part> parts = this.reader.readMono(elementType, request, emptyMap()).block(); assertNotNull(parts); FilePart part = (FilePart) parts.getFirst("fooPart"); assertNotNull(part); File dest = new File(System.getProperty("java.io.tmpdir") + "/" + part.filename()); part.transferTo(dest).block(Duration.ofSeconds(5)); assertTrue(dest.exists()); assertEquals(12, dest.length()); assertTrue(dest.delete()); }
/** * Convenience method to copy the content of the file in this part to the * given destination file. If the destination file already exists, it will * be truncated first. * <p>The default implementation delegates to {@link #transferTo(Path)}. * @param dest the target file * @return completion {@code Mono} with the result of the file transfer, * possibly {@link IllegalStateException} if the part isn't a file * @see #transferTo(Path) */ default Mono<Void> transferTo(File dest) { return transferTo(dest.toPath()); }
verticesFilePart.transferTo(verticesFile); edgesFilePart.transferTo(edgesFile);