@Override public File getFile() throws IOException { return this.delegate.getFile(); }
@Override public File getFile() throws IOException { return this.gzipped.getFile(); }
@Override public File getFile() throws IOException { return this.gzipped.getFile(); }
@Override public File getFile() throws IOException { return this.original.getFile(); }
@Override public File getFile() throws IOException { return this.encoded.getFile(); }
@Override public File getFile() throws IOException { return this.encoded.getFile(); }
@Override public File getFile() throws IOException { return this.original.getFile(); }
/** * Set the temporary directory where uploaded files get stored. * Default is the servlet container's temporary directory for the web application. * @see org.springframework.web.util.WebUtils#TEMP_DIR_CONTEXT_ATTRIBUTE */ public void setUploadTempDir(Resource uploadTempDir) throws IOException { if (!uploadTempDir.exists() && !uploadTempDir.getFile().mkdirs()) { throw new IllegalArgumentException("Given uploadTempDir [" + uploadTempDir + "] could not be created"); } this.fileItemFactory.setRepository(uploadTempDir.getFile()); this.uploadTempDirSpecified = true; }
@Override @Nullable public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not determine real path of resource " + resource, ex); } return null; } }
/** * This implementation returns a File reference for the given URI-identified * resource, provided that it refers to a file in the file system. * @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String) */ protected File getFile(URI uri) throws IOException { if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(uri).getFile(); } return ResourceUtils.getFile(uri, getDescription()); }
/** * This implementation returns a File reference for the underlying class path * resource, provided that it refers to a file in the file system. * @see org.springframework.util.ResourceUtils#getFile(java.net.URL, String) */ @Override public File getFile() throws IOException { URL url = getURL(); if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { return VfsResourceDelegate.getResource(url).getFile(); } return ResourceUtils.getFile(url, getDescription()); }
static void createGzippedFile(String filePath) throws IOException { Resource location = new ClassPathResource("test/", EncodedResourceResolverTests.class); Resource resource = new FileSystemResource(location.createRelative(filePath).getFile()); Path gzFilePath = Paths.get(resource.getFile().getAbsolutePath() + ".gz"); Files.deleteIfExists(gzFilePath); File gzFile = Files.createFile(gzFilePath).toFile(); GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile)); FileCopyUtils.copy(resource.getInputStream(), out); gzFile.deleteOnExit(); }
static void createGzippedFile(String filePath) throws IOException { Resource location = new ClassPathResource("test/", EncodedResourceResolverTests.class); Resource resource = new FileSystemResource(location.createRelative(filePath).getFile()); Path gzFilePath = Paths.get(resource.getFile().getAbsolutePath() + ".gz"); Files.deleteIfExists(gzFilePath); File gzFile = Files.createFile(gzFilePath).toFile(); GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile)); FileCopyUtils.copy(resource.getInputStream(), out); gzFile.deleteOnExit(); }
@Override @Nullable public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not determine real path of resource " + resource, ex); } return null; } }
@Test public void unmarshalFile() throws IOException { Resource resource = new ClassPathResource("jaxb2.xml", getClass()); File file = resource.getFile(); Flights f = (Flights) unmarshaller.unmarshal(new StreamSource(file)); testFlights(f); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { try { ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response; Resource logo = new ClassPathResource("spring.png", ZeroCopyIntegrationTests.class); File logoFile = logo.getFile(); zeroCopyResponse.getHeaders().setContentType(MediaType.IMAGE_PNG); zeroCopyResponse.getHeaders().setContentLength(logoFile.length()); return zeroCopyResponse.writeWith(logoFile, 0, logoFile.length()); } catch (Throwable ex) { return Mono.error(ex); } } }
@Test public void write() throws IOException { Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class); BufferedImage body = ImageIO.read(logo.getFile()); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); MediaType contentType = new MediaType("image", "png"); converter.write(body, contentType, outputMessage); assertEquals("Invalid content type", contentType, outputMessage.getWrittenHeaders().getContentType()); assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0); BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes())); assertEquals("Invalid height", 500, result.getHeight()); assertEquals("Invalid width", 750, result.getWidth()); }
@Test public void shouldWriteImageResource() throws IOException { MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Resource body = new ClassPathResource("logo.jpg", getClass()); converter.write(body, null, outputMessage); assertEquals("Invalid content-type", MediaType.IMAGE_JPEG, outputMessage.getHeaders().getContentType()); assertEquals("Invalid content-length", body.getFile().length(), outputMessage.getHeaders().getContentLength()); }
@Test public void writeDefaultContentType() throws IOException { Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class); MediaType contentType = new MediaType("image", "png"); converter.setDefaultContentType(contentType); BufferedImage body = ImageIO.read(logo.getFile()); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(body, new MediaType("*", "*"), outputMessage); assertEquals("Invalid content type", contentType, outputMessage.getWrittenHeaders().getContentType()); assertTrue("Invalid size", outputMessage.getBodyAsBytes().length > 0); BufferedImage result = ImageIO.read(new ByteArrayInputStream(outputMessage.getBodyAsBytes())); assertEquals("Invalid height", 500, result.getHeight()); assertEquals("Invalid width", 750, result.getWidth()); }
@Test public void marshalAttachments() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(BinaryObject.class); marshaller.setMtomEnabled(true); marshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.convertToXopPackage()).willReturn(true); byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream()); BinaryObject object = new BinaryObject(bytes, dataHandler); StringWriter writer = new StringWriter(); marshaller.marshal(object, new StreamResult(writer), mimeContainer); assertTrue("No XML written", writer.toString().length() > 0); verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class)); }