Skip to content

Commit cd37eca

Browse files
committed
ZIP: More Polishing
1 parent 0a5fedc commit cd37eca

File tree

12 files changed

+71
-75
lines changed

12 files changed

+71
-75
lines changed

spring-integration-zip/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following input data types can be **compressed**:
2626
* Iterable
2727

2828
In input data types can be mixed as part of an Iterable. E.g. you should be
29-
easily be able to compress a collection containing Strings, byte arrays and Files.
29+
easily able to compress a collection containing Strings, byte arrays and Files.
3030
It is important to note that nested Iterables are *NOT SUPPORTED* at present time.
3131

3232
The zip transformer can be customized by setting several properties:

spring-integration-zip/src/main/java/org/springframework/integration/zip/ZipHeaders.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,21 +17,17 @@
1717

1818
/**
1919
* Zip adapter specific message headers.
20-
*
2120
* @author Gunnar Hillert
2221
* @since 1.0
2322
*/
24-
public final class ZipHeaders {
23+
public abstract class ZipHeaders {
2524

26-
private static final String PREFIX = "zip_";
25+
public static final String PREFIX = "zip_";
2726

2827
public static final String ZIP_ENTRY_FILE_NAME = PREFIX + "entryFilename";
28+
2929
public static final String ZIP_ENTRY_PATH = PREFIX + "entryPath";
30-
public static final String ZIP_ENTRY_LAST_MODIFIED_DATE = PREFIX + "entryLastModifiedDate";
3130

32-
/** Noninstantiable utility class */
33-
private ZipHeaders() {
34-
throw new AssertionError();
35-
}
31+
public static final String ZIP_ENTRY_LAST_MODIFIED_DATE = PREFIX + "entryLastModifiedDate";
3632

3733
}

spring-integration-zip/src/main/java/org/springframework/integration/zip/config/xml/ZipNamespaceHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.integration.zip.config.xml;
1718

1819
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
@@ -26,9 +27,6 @@
2627
*/
2728
public class ZipNamespaceHandler extends AbstractIntegrationNamespaceHandler {
2829

29-
/* (non-Javadoc)
30-
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
31-
*/
3230
@Override
3331
public void init() {
3432
this.registerBeanDefinitionParser("zip-transformer", new ZipTransformerParser());
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.integration.zip.transformer.splitter;
17+
package org.springframework.integration.zip.splitter;
1818

1919
import java.util.ArrayList;
2020
import java.util.List;

spring-integration-zip/src/main/java/org/springframework/integration/zip/transformer/SpringZipUtils.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,10 +37,8 @@
3737
/**
3838
* Once the Spring Integration Zip support matures, we need to contribute the
3939
* methods in this utility class back to the ZT Zip project.
40-
*
4140
* @author Gunnar Hillert
4241
* @since 1.0
43-
*
4442
*/
4543
public class SpringZipUtils {
4644

@@ -60,18 +58,17 @@ public static byte[] pack(Collection<ZipEntrySource> entries, int compressionLev
6058
return outputStream.toByteArray();
6159
}
6260

63-
public static void pack(Collection<ZipEntrySource> entries, File zip,
64-
int compressionLevel) {
61+
public static void pack(Collection<ZipEntrySource> entries, File zip, int compressionLevel) {
6562

6663
if (logger.isDebugEnabled()) {
67-
logger.debug("Creating '" + zip + "' from "
68-
+ entries + ".");
64+
logger.debug("Creating '" + zip + "' from " + entries + ".");
6965
}
7066

7167
final FileOutputStream outputStream;
7268
try {
7369
outputStream = new FileOutputStream(zip);
74-
} catch (FileNotFoundException e) {
70+
}
71+
catch (FileNotFoundException e) {
7572
throw new IllegalStateException(String.format("File '%s' not found.", zip.getAbsolutePath()), e);
7673
}
7774

@@ -90,9 +87,11 @@ private static void pack(Collection<ZipEntrySource> entries, OutputStream output
9087
for (ZipEntrySource entry : entries) {
9188
addEntry(entry, out);
9289
}
93-
} catch (IOException e) {
90+
}
91+
catch (IOException e) {
9492
throw rethrow(e);
95-
} finally {
93+
}
94+
finally {
9695
IOUtils.closeQuietly(out);
9796
}
9897

@@ -105,7 +104,8 @@ private static void addEntry(ZipEntrySource entry, ZipOutputStream out)
105104
if (in != null) {
106105
try {
107106
IOUtils.copy(in, out);
108-
} finally {
107+
}
108+
finally {
109109
IOUtils.closeQuietly(in);
110110
}
111111
}
@@ -120,7 +120,8 @@ public static void copy(InputStream in, File file) throws IOException {
120120
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
121121
try {
122122
IOUtils.copy(in, out);
123-
} finally {
123+
}
124+
finally {
124125
IOUtils.closeQuietly(out);
125126
}
126127
}
@@ -134,16 +135,13 @@ static boolean isValid(final File file) {
134135
try {
135136
zipfile = new ZipFile(file);
136137
return true;
137-
} catch (IOException e) {
138+
}
139+
catch (IOException e) {
138140
return false;
139-
} finally {
140-
try {
141-
if (zipfile != null) {
142-
zipfile.close();
143-
zipfile = null;
144-
}
145-
} catch (IOException e) {
146-
}
141+
}
142+
finally {
143+
IOUtils.closeQuietly(zipfile);
147144
}
148145
}
146+
149147
}

spring-integration-zip/src/main/resources/org/springframework/integration/zip/config/spring-integration-zip-1.0.xsd

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
schemaLocation="http://www.springframework.org/schema/integration/spring-integration.xsd" />
1313

1414
<xsd:annotation>
15-
<xsd:documentation><![CDATA[
15+
<xsd:documentation>
1616
Defines the configuration elements for the Spring Integration
1717
Zip Adapter.
18-
]]></xsd:documentation>
18+
</xsd:documentation>
1919
</xsd:annotation>
2020

2121
<xsd:element name="zip-transformer">
@@ -74,25 +74,27 @@
7474
</xsd:sequence>
7575
<xsd:attribute name="id" type="xsd:string">
7676
<xsd:annotation>
77-
<xsd:documentation><![CDATA[Identifies the underlying Spring bean definition (EventDrivenConsumer)]]></xsd:documentation>
77+
<xsd:documentation>
78+
Identifies the underlying Spring bean definition (EventDrivenConsumer)
79+
</xsd:documentation>
7880
</xsd:annotation>
7981
</xsd:attribute>
8082
<xsd:attributeGroup ref="integration:inputOutputChannelGroup"/>
8183
<xsd:attribute name="delete-files" type="xsd:string">
8284
<xsd:annotation>
8385
<xsd:documentation>
84-
<![CDATA[If the payload is an instance of {@link File}, this
86+
If the payload is an instance of {@link File}, this
8587
attribute specifies whether to delete the {@link File} after
86-
transformation. The default is 'false'.]]>
88+
transformation. The default is 'false'.
8789
</xsd:documentation>
8890
</xsd:annotation>
8991
</xsd:attribute>
9092
<xsd:attribute name="expect-single-result" type="xsd:string">
9193
<xsd:annotation>
9294
<xsd:documentation>
93-
<![CDATA[If set to 'true', this property indicates
95+
If set to 'true', this property indicates
9496
that only one result object shall be returned as a result
95-
from the executed Unzip operation. Defaults to 'false'.]]>
97+
from the executed Unzip operation. Defaults to 'false'.
9698
</xsd:documentation>
9799
</xsd:annotation>
98100
</xsd:attribute>

spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
<int:chain input-channel="input" output-channel="out">
1717
<int-zip:unzip-transformer result-type="BYTE_ARRAY"/>
18-
<int:splitter method="splitUnzippedMap">
19-
<bean class="org.springframework.integration.zip.transformer.splitter.UnZipResultSplitter"/>
18+
<int:splitter>
19+
<bean class="org.springframework.integration.zip.splitter.UnZipResultSplitter"/>
2020
</int:splitter>
2121
</int:chain>
2222

spring-integration-zip/src/test/java/org/springframework/integration/zip/UnZip2FileTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,10 +25,10 @@
2525
import org.junit.After;
2626
import org.junit.Assert;
2727
import org.junit.Before;
28-
import org.junit.Ignore;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130
import org.junit.rules.TemporaryFolder;
31+
3232
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3333
import org.springframework.context.annotation.Bean;
3434
import org.springframework.context.annotation.Configuration;
@@ -60,29 +60,28 @@ public class UnZip2FileTests {
6060

6161
@Before
6262
public void setup() throws IOException {
63-
this.workDir = testFolder.newFolder();
64-
properties.put("workDir", workDir);
63+
this.workDir = this.testFolder.newFolder();
64+
properties.put("workDir", this.workDir);
6565
System.out.print(this.workDir.getAbsolutePath());
6666

67-
context = new AnnotationConfigApplicationContext();
68-
context.register(ContextConfiguration.class);
69-
context.refresh();
70-
input = context.getBean("input", MessageChannel.class);
71-
resourceLoader = context;
67+
this.context = new AnnotationConfigApplicationContext();
68+
this.context.register(ContextConfiguration.class);
69+
this.context.refresh();
70+
this.input = this.context.getBean("input", MessageChannel.class);
71+
this.resourceLoader = this.context;
7272
}
7373

7474
@After
7575
public void cleanup() {
76-
if (context != null) {
77-
context.close();
76+
if (this.context != null) {
77+
this.context.close();
7878
}
7979
}
8080

8181
@Test
82-
@Ignore
8382
public void unZipWithOneEntry() throws Exception {
8483

85-
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
84+
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip");
8685
final InputStream is = resource.getInputStream();
8786

8887
byte[] zipdata = IOUtils.toByteArray(is);
@@ -157,4 +156,5 @@ Properties properties() throws IOException {
157156
}
158157

159158
}
159+
160160
}

spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/UnZipTransformerParserTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -10,6 +10,7 @@
1010
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
* specific language governing permissions and limitations under the License.
1212
*/
13+
1314
package org.springframework.integration.zip.config.xml;
1415

1516
import static org.junit.Assert.assertEquals;
@@ -45,7 +46,7 @@ public class UnZipTransformerParserTests {
4546
private ConfigurableApplicationContext context;
4647

4748
@Test
48-
public void testUnZiptransformerParserWithDefaults() {
49+
public void testUnZipTransformerParserWithDefaults() {
4950

5051
setUp("UnZipTransformerParserTests.xml", getClass());
5152

@@ -86,7 +87,7 @@ public void testUnZiptransformerParserWithDefaults() {
8687
}
8788

8889
@Test
89-
public void testUnZiptransformerParserWithExplicitSettings() {
90+
public void testUnZipTransformerParserWithExplicitSettings() {
9091

9192
setUp("UnZipTransformerParserTests.xml", getClass());
9293

spring-integration-zip/src/test/java/org/springframework/integration/zip/config/xml/ZipTransformerParserTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -10,6 +10,7 @@
1010
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1111
* specific language governing permissions and limitations under the License.
1212
*/
13+
1314
package org.springframework.integration.zip.config.xml;
1415

1516
import static org.hamcrest.Matchers.containsString;
@@ -49,7 +50,7 @@ public class ZipTransformerParserTests {
4950
private ConfigurableApplicationContext context;
5051

5152
@Test
52-
public void testZiptransformerParserWithDefaults() {
53+
public void testZipTransformerParserWithDefaults() {
5354

5455
setUp("ZipTransformerParserTests.xml", getClass());
5556

@@ -90,7 +91,7 @@ public void testZiptransformerParserWithDefaults() {
9091
}
9192

9293
@Test
93-
public void testZiptransformerParserWithExplicitSettings() {
94+
public void testZipTransformerParserWithExplicitSettings() {
9495

9596
setUp("ZipTransformerParserTests.xml", getClass());
9697

0 commit comments

Comments
 (0)