Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ea519477
Commit
ea519477
authored
Nov 05, 2019
by
Johnny Lim
Committed by
Stephane Nicoll
Nov 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use try-with-resources blocks in JarFileArchiveTests
See gh-18883
parent
471ca01c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
49 deletions
+49
-49
JarFileArchiveTests.java
...ingframework/boot/loader/archive/JarFileArchiveTests.java
+49
-49
No files found.
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java
View file @
ea519477
...
@@ -98,48 +98,48 @@ class JarFileArchiveTests {
...
@@ -98,48 +98,48 @@ class JarFileArchiveTests {
@Test
@Test
void
getNestedArchive
()
throws
Exception
{
void
getNestedArchive
()
throws
Exception
{
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
try
(
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
))
{
assertThat
(
nested
.
getUrl
().
toString
()).
isEqualTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/nested.jar!/"
);
assertThat
(
nested
.
getUrl
().
toString
()).
isEqualTo
(
"jar:"
+
this
.
rootJarFileUrl
+
"!/nested.jar!/"
);
((
JarFileArchive
)
nested
).
close
();
}
}
}
@Test
@Test
void
getNestedUnpackedArchive
()
throws
Exception
{
void
getNestedUnpackedArchive
()
throws
Exception
{
setup
(
true
);
setup
(
true
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
);
try
(
Archive
nested
=
this
.
archive
.
getNestedArchive
(
entry
))
{
assertThat
(
nested
.
getUrl
().
toString
()).
startsWith
(
"file:"
);
assertThat
(
nested
.
getUrl
().
toString
()).
startsWith
(
"file:"
);
assertThat
(
nested
.
getUrl
().
toString
()).
endsWith
(
"/nested.jar"
);
assertThat
(
nested
.
getUrl
().
toString
()).
endsWith
(
"/nested.jar"
);
((
JarFileArchive
)
nested
).
close
();
}
}
}
@Test
@Test
void
unpackedLocationsAreUniquePerArchive
()
throws
Exception
{
void
unpackedLocationsAreUniquePerArchive
()
throws
Exception
{
setup
(
true
);
setup
(
true
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Entry
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
firstNested
=
this
.
archive
.
getNestedArchive
(
entry
);
URL
firstNestedUrl
;
URL
firstNestedUrl
=
firstNested
.
getUrl
();
try
(
Archive
firstNested
=
this
.
archive
.
getNestedArchive
(
entry
))
{
((
JarFileArchive
)
firstNested
).
close
();
firstNestedUrl
=
firstNested
.
getUrl
();
}
this
.
archive
.
close
();
this
.
archive
.
close
();
setup
(
true
);
setup
(
true
);
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
entry
=
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
);
Archive
secondNested
=
this
.
archive
.
getNestedArchive
(
entry
);
try
(
Archive
secondNested
=
this
.
archive
.
getNestedArchive
(
entry
))
{
URL
secondNestedUrl
=
secondNested
.
getUrl
();
URL
secondNestedUrl
=
secondNested
.
getUrl
();
assertThat
(
secondNestedUrl
).
isNotEqualTo
(
firstNestedUrl
);
assertThat
(
secondNestedUrl
).
isNotEqualTo
(
firstNestedUrl
);
((
JarFileArchive
)
secondNested
).
close
();
}
}
}
@Test
@Test
void
unpackedLocationsFromSameArchiveShareSameParent
()
throws
Exception
{
void
unpackedLocationsFromSameArchiveShareSameParent
()
throws
Exception
{
setup
(
true
);
setup
(
true
);
Archive
nestedArchive
=
this
.
archive
.
getNestedArchive
(
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
));
try
(
Archive
nestedArchive
=
this
.
archive
.
getNestedArchive
(
getEntriesMap
(
this
.
archive
).
get
(
"nested.jar"
));
File
nested
=
new
File
(
nestedArchive
.
getUrl
().
toURI
());
Archive
anotherNestedArchive
=
this
.
archive
Archive
anotherNestedArchive
=
this
.
archive
.
getNestedArchive
(
getEntriesMap
(
this
.
archive
).
get
(
"another-nested.jar"
)))
{
.
getNestedArchive
(
getEntriesMap
(
this
.
archive
).
get
(
"another-nested.jar"
));
File
nested
=
new
File
(
nestedArchive
.
getUrl
().
toURI
());
File
anotherNested
=
new
File
(
anotherNestedArchive
.
getUrl
().
toURI
());
File
anotherNested
=
new
File
(
anotherNestedArchive
.
getUrl
().
toURI
());
assertThat
(
nested
.
getParent
()).
isEqualTo
(
anotherNested
.
getParent
());
assertThat
(
nested
.
getParent
()).
isEqualTo
(
anotherNested
.
getParent
());
((
JarFileArchive
)
nestedArchive
).
close
();
}
((
JarFileArchive
)
anotherNestedArchive
).
close
();
}
}
@Test
@Test
...
@@ -156,40 +156,40 @@ class JarFileArchiveTests {
...
@@ -156,40 +156,40 @@ class JarFileArchiveTests {
}
}
@Test
@Test
void
nestedZip64ArchivesAreHandledGracefully
()
throws
IO
Exception
{
void
nestedZip64ArchivesAreHandledGracefully
()
throws
Exception
{
File
file
=
new
File
(
this
.
tempDir
,
"test.jar"
);
File
file
=
new
File
(
this
.
tempDir
,
"test.jar"
);
JarOutputStream
output
=
new
JarOutputStream
(
new
FileOutputStream
(
file
));
try
(
JarOutputStream
output
=
new
JarOutputStream
(
new
FileOutputStream
(
file
)))
{
JarEntry
zip64JarEntry
=
new
JarEntry
(
"nested/zip64.jar"
);
JarEntry
zip64JarEntry
=
new
JarEntry
(
"nested/zip64.jar"
);
output
.
putNextEntry
(
zip64JarEntry
);
output
.
putNextEntry
(
zip64JarEntry
);
byte
[]
zip64JarData
=
writeZip64Jar
();
byte
[]
zip64JarData
=
writeZip64Jar
();
zip64JarEntry
.
setSize
(
zip64JarData
.
length
);
zip64JarEntry
.
setSize
(
zip64JarData
.
length
);
zip64JarEntry
.
setCompressedSize
(
zip64JarData
.
length
);
zip64JarEntry
.
setCompressedSize
(
zip64JarData
.
length
);
zip64JarEntry
.
setMethod
(
ZipEntry
.
STORED
);
zip64JarEntry
.
setMethod
(
ZipEntry
.
STORED
);
CRC32
crc32
=
new
CRC32
();
CRC32
crc32
=
new
CRC32
();
crc32
.
update
(
zip64JarData
);
crc32
.
update
(
zip64JarData
);
zip64JarEntry
.
setCrc
(
crc32
.
getValue
());
zip64JarEntry
.
setCrc
(
crc32
.
getValue
());
output
.
write
(
zip64JarData
);
output
.
write
(
zip64JarData
);
output
.
closeEntry
();
output
.
closeEntry
();
output
.
close
();
}
JarFileArchive
jarFileArchive
=
new
JarFileArchive
(
file
);
try
(
JarFileArchive
jarFileArchive
=
new
JarFileArchive
(
file
);
Archive
nestedArchive
=
jarFileArchive
.
getNestedArchive
(
getEntriesMap
(
jarFileArchive
).
get
(
"nested/zip64.jar"
));
Archive
nestedArchive
=
jarFileArchive
Iterator
<
Entry
>
it
=
nestedArchive
.
iterator
();
.
getNestedArchive
(
getEntriesMap
(
jarFileArchive
).
get
(
"nested/zip64.jar"
)))
{
for
(
int
i
=
0
;
i
<
65537
;
i
++)
{
Iterator
<
Entry
>
it
=
nestedArchive
.
iterator
();
assertThat
(
it
.
hasNext
()).
as
(
i
+
"nth file is present"
).
isTrue
();
for
(
int
i
=
0
;
i
<
65537
;
i
++)
{
it
.
next
();
assertThat
(
it
.
hasNext
()).
as
(
i
+
"nth file is present"
).
isTrue
();
it
.
next
();
}
}
}
((
JarFileArchive
)
nestedArchive
).
close
();
jarFileArchive
.
close
();
}
}
private
byte
[]
writeZip64Jar
()
throws
IOException
{
private
byte
[]
writeZip64Jar
()
throws
IOException
{
ByteArrayOutputStream
bytes
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
bytes
=
new
ByteArrayOutputStream
();
JarOutputStream
jarOutput
=
new
JarOutputStream
(
bytes
);
try
(
JarOutputStream
jarOutput
=
new
JarOutputStream
(
bytes
))
{
for
(
int
i
=
0
;
i
<
65537
;
i
++)
{
for
(
int
i
=
0
;
i
<
65537
;
i
++)
{
jarOutput
.
putNextEntry
(
new
JarEntry
(
i
+
".dat"
));
jarOutput
.
putNextEntry
(
new
JarEntry
(
i
+
".dat"
));
jarOutput
.
closeEntry
();
jarOutput
.
closeEntry
();
}
}
}
jarOutput
.
close
();
return
bytes
.
toByteArray
();
return
bytes
.
toByteArray
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment