diff --git a/spring-integration-zip/README.md b/spring-integration-zip/README.md index 306d04f..aedaa4b 100644 --- a/spring-integration-zip/README.md +++ b/spring-integration-zip/README.md @@ -26,7 +26,7 @@ The following input data types can be **compressed**: * Iterable In input data types can be mixed as part of an Iterable. E.g. you should be -easily be able to compress a collection containing Strings, byte arrays and Files. +easily able to compress a collection containing Strings, byte arrays and Files. It is important to note that nested Iterables are *NOT SUPPORTED* at present time. The zip transformer can be customized by setting several properties: diff --git a/spring-integration-zip/src/main/java/org/springframework/integration/zip/ZipHeaders.java b/spring-integration-zip/src/main/java/org/springframework/integration/zip/ZipHeaders.java index 1b1fe01..4b8adbf 100644 --- a/spring-integration-zip/src/main/java/org/springframework/integration/zip/ZipHeaders.java +++ b/spring-integration-zip/src/main/java/org/springframework/integration/zip/ZipHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,21 +17,17 @@ package org.springframework.integration.zip; /** * Zip adapter specific message headers. - * * @author Gunnar Hillert * @since 1.0 */ -public final class ZipHeaders { +public abstract class ZipHeaders { - private static final String PREFIX = "zip_"; + public static final String PREFIX = "zip_"; public static final String ZIP_ENTRY_FILE_NAME = PREFIX + "entryFilename"; + public static final String ZIP_ENTRY_PATH = PREFIX + "entryPath"; + public static final String ZIP_ENTRY_LAST_MODIFIED_DATE = PREFIX + "entryLastModifiedDate"; - /** Noninstantiable utility class */ - private ZipHeaders() { - throw new AssertionError(); - } - } diff --git a/spring-integration-zip/src/main/java/org/springframework/integration/zip/config/xml/ZipNamespaceHandler.java b/spring-integration-zip/src/main/java/org/springframework/integration/zip/config/xml/ZipNamespaceHandler.java index 6ef92e5..3c02af7 100644 --- a/spring-integration-zip/src/main/java/org/springframework/integration/zip/config/xml/ZipNamespaceHandler.java +++ b/spring-integration-zip/src/main/java/org/springframework/integration/zip/config/xml/ZipNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.zip.config.xml; import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; @@ -26,9 +27,6 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa */ public class ZipNamespaceHandler extends AbstractIntegrationNamespaceHandler { - /* (non-Javadoc) - * @see org.springframework.beans.factory.xml.NamespaceHandler#init() - */ @Override public void init() { this.registerBeanDefinitionParser("zip-transformer", new ZipTransformerParser()); diff --git a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/splitter/UnZipResultSplitter.java b/spring-integration-zip/src/main/java/org/springframework/integration/zip/splitter/UnZipResultSplitter.java similarity index 96% rename from spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/splitter/UnZipResultSplitter.java rename to spring-integration-zip/src/main/java/org/springframework/integration/zip/splitter/UnZipResultSplitter.java index 3c50853..5af9995 100644 --- a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/splitter/UnZipResultSplitter.java +++ b/spring-integration-zip/src/main/java/org/springframework/integration/zip/splitter/UnZipResultSplitter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.zip.transformer.splitter; +package org.springframework.integration.zip.splitter; import java.util.ArrayList; import java.util.List; diff --git a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/SpringZipUtils.java b/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/SpringZipUtils.java index f1f2539..c706e67 100644 --- a/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/SpringZipUtils.java +++ b/spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/SpringZipUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,10 +37,8 @@ import org.zeroturnaround.zip.ZipException; /** * Once the Spring Integration Zip support matures, we need to contribute the * methods in this utility class back to the ZT Zip project. - * * @author Gunnar Hillert * @since 1.0 - * */ public class SpringZipUtils { @@ -60,18 +58,17 @@ public class SpringZipUtils { return outputStream.toByteArray(); } - public static void pack(Collection entries, File zip, - int compressionLevel) { + public static void pack(Collection entries, File zip, int compressionLevel) { if (logger.isDebugEnabled()) { - logger.debug("Creating '" + zip + "' from " - + entries + "."); + logger.debug("Creating '" + zip + "' from " + entries + "."); } final FileOutputStream outputStream; try { outputStream = new FileOutputStream(zip); - } catch (FileNotFoundException e) { + } + catch (FileNotFoundException e) { throw new IllegalStateException(String.format("File '%s' not found.", zip.getAbsolutePath()), e); } @@ -90,9 +87,11 @@ public class SpringZipUtils { for (ZipEntrySource entry : entries) { addEntry(entry, out); } - } catch (IOException e) { + } + catch (IOException e) { throw rethrow(e); - } finally { + } + finally { IOUtils.closeQuietly(out); } @@ -105,7 +104,8 @@ public class SpringZipUtils { if (in != null) { try { IOUtils.copy(in, out); - } finally { + } + finally { IOUtils.closeQuietly(in); } } @@ -120,7 +120,8 @@ public class SpringZipUtils { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { IOUtils.copy(in, out); - } finally { + } + finally { IOUtils.closeQuietly(out); } } @@ -134,16 +135,13 @@ public class SpringZipUtils { try { zipfile = new ZipFile(file); return true; - } catch (IOException e) { + } + catch (IOException e) { return false; - } finally { - try { - if (zipfile != null) { - zipfile.close(); - zipfile = null; - } - } catch (IOException e) { - } + } + finally { + IOUtils.closeQuietly(zipfile); } } + } diff --git a/spring-integration-zip/src/main/resources/org/springframework/integration/zip/config/spring-integration-zip-1.0.xsd b/spring-integration-zip/src/main/resources/org/springframework/integration/zip/config/spring-integration-zip-1.0.xsd index 23d2546..3ea1627 100644 --- a/spring-integration-zip/src/main/resources/org/springframework/integration/zip/config/spring-integration-zip-1.0.xsd +++ b/spring-integration-zip/src/main/resources/org/springframework/integration/zip/config/spring-integration-zip-1.0.xsd @@ -12,10 +12,10 @@ schemaLocation="http://www.springframework.org/schema/integration/spring-integration.xsd" /> - Defines the configuration elements for the Spring Integration Zip Adapter. - ]]> + @@ -74,25 +74,27 @@ - + + Identifies the underlying Spring bean definition (EventDrivenConsumer) + - + transformation. The default is 'false'. - + from the executed Unzip operation. Defaults to 'false'. diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests-context.xml b/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests-context.xml index fb21f1e..ab52350 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests-context.xml +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests-context.xml @@ -15,8 +15,8 @@ - - + + diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests.java b/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests.java index 3d4d14c..2eae50a 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests.java +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +25,10 @@ import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; + import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -60,29 +60,28 @@ public class UnZip2FileTests { @Before public void setup() throws IOException { - this.workDir = testFolder.newFolder(); - properties.put("workDir", workDir); + this.workDir = this.testFolder.newFolder(); + properties.put("workDir", this.workDir); System.out.print(this.workDir.getAbsolutePath()); - context = new AnnotationConfigApplicationContext(); - context.register(ContextConfiguration.class); - context.refresh(); - input = context.getBean("input", MessageChannel.class); - resourceLoader = context; + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ContextConfiguration.class); + this.context.refresh(); + this.input = this.context.getBean("input", MessageChannel.class); + this.resourceLoader = this.context; } @After public void cleanup() { - if (context != null) { - context.close(); + if (this.context != null) { + this.context.close(); } } @Test - @Ignore public void unZipWithOneEntry() throws Exception { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip"); final InputStream is = resource.getInputStream(); byte[] zipdata = IOUtils.toByteArray(is); @@ -157,4 +156,5 @@ public class UnZip2FileTests { } } + } diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/UnZipTransformerParserTests.java b/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/UnZipTransformerParserTests.java index 179e8e8..9e9e431 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/UnZipTransformerParserTests.java +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/UnZipTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -10,6 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ + package org.springframework.integration.zip.config.xml; import static org.junit.Assert.assertEquals; @@ -45,7 +46,7 @@ public class UnZipTransformerParserTests { private ConfigurableApplicationContext context; @Test - public void testUnZiptransformerParserWithDefaults() { + public void testUnZipTransformerParserWithDefaults() { setUp("UnZipTransformerParserTests.xml", getClass()); @@ -86,7 +87,7 @@ public class UnZipTransformerParserTests { } @Test - public void testUnZiptransformerParserWithExplicitSettings() { + public void testUnZipTransformerParserWithExplicitSettings() { setUp("UnZipTransformerParserTests.xml", getClass()); diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/ZipTransformerParserTests.java b/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/ZipTransformerParserTests.java index fdc6869..119983e 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/ZipTransformerParserTests.java +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/ZipTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -10,6 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ + package org.springframework.integration.zip.config.xml; import static org.hamcrest.Matchers.containsString; @@ -49,7 +50,7 @@ public class ZipTransformerParserTests { private ConfigurableApplicationContext context; @Test - public void testZiptransformerParserWithDefaults() { + public void testZipTransformerParserWithDefaults() { setUp("ZipTransformerParserTests.xml", getClass()); @@ -90,7 +91,7 @@ public class ZipTransformerParserTests { } @Test - public void testZiptransformerParserWithExplicitSettings() { + public void testZipTransformerParserWithExplicitSettings() { setUp("ZipTransformerParserTests.xml", getClass()); diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/UnZipTransformerTests.java b/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/UnZipTransformerTests.java index 1653a04..26864b7 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/UnZipTransformerTests.java +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/UnZipTransformerTests.java @@ -73,7 +73,7 @@ public class UnZipTransformerTests { @Test public void unzipSingleFileAsInputStreamToByteArray() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip"); final InputStream is = resource.getInputStream(); final Message message = MessageBuilder.withPayload(is).build(); @@ -103,7 +103,7 @@ public class UnZipTransformerTests { @Test public void unzipSingleFileToByteArray() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip"); final InputStream is = resource.getInputStream(); final File inputFile = new File(this.workDir, "unzipSingleFileToByteArray"); @@ -138,7 +138,7 @@ public class UnZipTransformerTests { @Test public void unzipSingleFileToByteArrayWithDeleteFilesTrue() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip"); final InputStream is = resource.getInputStream(); final File inputFile = new File(this.workDir, "unzipSingleFileToByteArray"); @@ -177,7 +177,7 @@ public class UnZipTransformerTests { @Test public void unzipMultipleFilesAsInputStreamToByteArray() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/countries.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/countries.zip"); final InputStream is = resource.getInputStream(); final Message message = MessageBuilder.withPayload(is).build(); @@ -205,9 +205,9 @@ public class UnZipTransformerTests { * @throws IOException */ @Test - public void unzipMultipleFilesAsInputstreamWithExpectSingleResultTrue() throws IOException { + public void unzipMultipleFilesAsInputStreamWithExpectSingleResultTrue() throws IOException { - final Resource resource = resourceLoader.getResource("classpath:testzipdata/countries.zip"); + final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/countries.zip"); final InputStream is = resource.getInputStream(); final Message message = MessageBuilder.withPayload(is).build(); @@ -233,7 +233,7 @@ public class UnZipTransformerTests { @Test public void unzipInvalidZipFile() throws IOException, InterruptedException { - File fileToUnzip = testFolder.newFile(); + File fileToUnzip = this.testFolder.newFile(); FileUtils.writeStringToFile(fileToUnzip, "hello world"); UnZipTransformer unZipTransformer = new UnZipTransformer(); diff --git a/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/ZipTransformerTests.java b/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/ZipTransformerTests.java index 4b9632c..323980f 100644 --- a/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/ZipTransformerTests.java +++ b/spring-integration-zip/src/test/java/org/springframework/integration/zip/transformer/ZipTransformerTests.java @@ -148,7 +148,8 @@ public class ZipTransformerTests { Assert.assertTrue(file.isFile()); //See http://stackoverflow.com/questions/3725662/what-is-the-earliest-timestamp-value-that-is-supported-in-zip-file-format - Assert.assertTrue(String.format("%s : %s", fileDate.getTime() - 4000, file.lastModified()), (fileDate.getTime() - 4000) < file.lastModified()); + Assert.assertTrue(String.format("%s : %s", fileDate.getTime() - 4000, file.lastModified()), + (fileDate.getTime() - 4000) < file.lastModified()); Assert.assertTrue((fileDate.getTime() + 4000) > file.lastModified()); Assert.assertTrue( @@ -241,8 +242,7 @@ public class ZipTransformerTests { zipTransformer.setBeanFactory(mock(BeanFactory.class)); zipTransformer.afterPropertiesSet(); - final Message> message = MessageBuilder.withPayload(files) - .build(); + final Message> message = MessageBuilder.withPayload(files).build(); final Message result = zipTransformer.transform(message); @@ -259,7 +259,7 @@ public class ZipTransformerTests { private File createTestFile(int size) throws IOException { - final File temporaryTestDirectory = testFolder.newFolder(); + final File temporaryTestDirectory = this.testFolder.newFolder(); final File testFile = new File(temporaryTestDirectory, "testdata" + UUID.randomUUID().toString() + ".data");