|
|
|
|
@ -19,6 +19,7 @@ package org.springframework.web.reactive.resource;
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.resource;
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.UncheckedIOException; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
import java.nio.file.Paths; |
|
|
|
|
@ -26,7 +27,6 @@ import java.util.HashSet;
@@ -26,7 +27,6 @@ import java.util.HashSet;
|
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.zip.GZIPOutputStream; |
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.extension.AfterEachCallback; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtensionContext; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtensionContext.Namespace; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtensionContext.Store; |
|
|
|
|
@ -40,21 +40,13 @@ import org.springframework.util.FileCopyUtils;
@@ -40,21 +40,13 @@ import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Andy Wilkinson |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
* @since 5.2.2 |
|
|
|
|
*/ |
|
|
|
|
class GzipSupport implements AfterEachCallback, ParameterResolver { |
|
|
|
|
class GzipSupport implements ParameterResolver { |
|
|
|
|
|
|
|
|
|
private static final Namespace namespace = Namespace.create(GzipSupport.class); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void afterEach(ExtensionContext context) { |
|
|
|
|
GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class); |
|
|
|
|
if (gzippedFiles != null) { |
|
|
|
|
for (File gzippedFile: gzippedFiles.created) { |
|
|
|
|
gzippedFile.delete(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { |
|
|
|
|
@ -70,13 +62,14 @@ class GzipSupport implements AfterEachCallback, ParameterResolver {
@@ -70,13 +62,14 @@ class GzipSupport implements AfterEachCallback, ParameterResolver {
|
|
|
|
|
return extensionContext.getStore(namespace); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class GzippedFiles { |
|
|
|
|
|
|
|
|
|
static class GzippedFiles implements AutoCloseable { |
|
|
|
|
|
|
|
|
|
private final Set<File> created = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
void create(String filePath) { |
|
|
|
|
try { |
|
|
|
|
Resource location = new ClassPathResource("test/", EncodedResourceResolverTests.class); |
|
|
|
|
Resource location = new ClassPathResource("test/", getClass()); |
|
|
|
|
Resource resource = new FileSystemResource(location.createRelative(filePath).getFile()); |
|
|
|
|
|
|
|
|
|
Path gzFilePath = Paths.get(resource.getFile().getAbsolutePath() + ".gz"); |
|
|
|
|
@ -85,13 +78,19 @@ class GzipSupport implements AfterEachCallback, ParameterResolver {
@@ -85,13 +78,19 @@ class GzipSupport implements AfterEachCallback, ParameterResolver {
|
|
|
|
|
File gzFile = Files.createFile(gzFilePath).toFile(); |
|
|
|
|
GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile)); |
|
|
|
|
FileCopyUtils.copy(resource.getInputStream(), out); |
|
|
|
|
created.add(gzFile); |
|
|
|
|
this.created.add(gzFile); |
|
|
|
|
} |
|
|
|
|
catch (IOException ex) { |
|
|
|
|
throw new RuntimeException(ex); |
|
|
|
|
throw new UncheckedIOException(ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void close() { |
|
|
|
|
for (File file: this.created) { |
|
|
|
|
file.delete(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|