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
2833f603
Commit
2833f603
authored
Jun 12, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid leaving streams open when writing libraries
Fixes gh-17115
parent
7103eab2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
JarWriter.java
...java/org/springframework/boot/loader/tools/JarWriter.java
+13
-13
No files found.
spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarWriter.java
View file @
2833f603
...
@@ -134,7 +134,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -134,7 +134,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
entries
.
nextElement
());
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
entries
.
nextElement
());
setUpEntry
(
jarFile
,
entry
);
setUpEntry
(
jarFile
,
entry
);
try
(
ZipHeaderPeekInputStream
inputStream
=
new
ZipHeaderPeekInputStream
(
jarFile
.
getInputStream
(
entry
)))
{
try
(
ZipHeaderPeekInputStream
inputStream
=
new
ZipHeaderPeekInputStream
(
jarFile
.
getInputStream
(
entry
)))
{
EntryWriter
entryWriter
=
new
InputStreamEntryWriter
(
inputStream
,
true
);
EntryWriter
entryWriter
=
new
InputStreamEntryWriter
(
inputStream
);
JarArchiveEntry
transformedEntry
=
entryTransformer
.
transform
(
entry
);
JarArchiveEntry
transformedEntry
=
entryTransformer
.
transform
(
entry
);
if
(
transformedEntry
!=
null
)
{
if
(
transformedEntry
!=
null
)
{
writeEntry
(
transformedEntry
,
entryWriter
,
unpackHandler
);
writeEntry
(
transformedEntry
,
entryWriter
,
unpackHandler
);
...
@@ -163,7 +163,12 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -163,7 +163,12 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
@Override
@Override
public
void
writeEntry
(
String
entryName
,
InputStream
inputStream
)
throws
IOException
{
public
void
writeEntry
(
String
entryName
,
InputStream
inputStream
)
throws
IOException
{
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
entryName
);
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
entryName
);
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
inputStream
,
true
));
try
{
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
inputStream
));
}
finally
{
inputStream
.
close
();
}
}
}
/**
/**
...
@@ -177,8 +182,9 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -177,8 +182,9 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
destination
+
library
.
getName
());
JarArchiveEntry
entry
=
new
JarArchiveEntry
(
destination
+
library
.
getName
());
entry
.
setTime
(
getNestedLibraryTime
(
file
));
entry
.
setTime
(
getNestedLibraryTime
(
file
));
new
CrcAndSize
(
file
).
setupStoredEntry
(
entry
);
new
CrcAndSize
(
file
).
setupStoredEntry
(
entry
);
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
new
FileInputStream
(
file
),
true
),
try
(
FileInputStream
input
=
new
FileInputStream
(
file
))
{
new
LibraryUnpackHandler
(
library
));
writeEntry
(
entry
,
new
InputStreamEntryWriter
(
input
),
new
LibraryUnpackHandler
(
library
));
}
}
}
private
long
getNestedLibraryTime
(
File
file
)
{
private
long
getNestedLibraryTime
(
File
file
)
{
...
@@ -221,7 +227,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -221,7 +227,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
JarEntry
entry
;
JarEntry
entry
;
while
((
entry
=
inputStream
.
getNextJarEntry
())
!=
null
)
{
while
((
entry
=
inputStream
.
getNextJarEntry
())
!=
null
)
{
if
(
entry
.
getName
().
endsWith
(
".class"
))
{
if
(
entry
.
getName
().
endsWith
(
".class"
))
{
writeEntry
(
new
JarArchiveEntry
(
entry
),
new
InputStreamEntryWriter
(
inputStream
,
false
));
writeEntry
(
new
JarArchiveEntry
(
entry
),
new
InputStreamEntryWriter
(
inputStream
));
}
}
}
}
}
}
...
@@ -283,7 +289,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -283,7 +289,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
entryWriter
.
write
(
output
);
entryWriter
.
write
(
output
);
entry
.
setComment
(
"UNPACK:"
+
unpackHandler
.
sha1Hash
(
entry
.
getName
()));
entry
.
setComment
(
"UNPACK:"
+
unpackHandler
.
sha1Hash
(
entry
.
getName
()));
return
new
InputStreamEntryWriter
(
new
ByteArrayInputStream
(
output
.
toByteArray
())
,
true
);
return
new
InputStreamEntryWriter
(
new
ByteArrayInputStream
(
output
.
toByteArray
()));
}
}
/**
/**
...
@@ -307,11 +313,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -307,11 +313,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
private
final
InputStream
inputStream
;
private
final
InputStream
inputStream
;
private
final
boolean
close
;
InputStreamEntryWriter
(
InputStream
inputStream
)
{
InputStreamEntryWriter
(
InputStream
inputStream
,
boolean
close
)
{
this
.
inputStream
=
inputStream
;
this
.
inputStream
=
inputStream
;
this
.
close
=
close
;
}
}
@Override
@Override
...
@@ -322,9 +325,6 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
...
@@ -322,9 +325,6 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
}
outputStream
.
flush
();
outputStream
.
flush
();
if
(
this
.
close
)
{
this
.
inputStream
.
close
();
}
}
}
}
}
...
...
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