Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
asm
asm
Commits
788219ce
Commit
788219ce
authored
May 28, 2021
by
Eric Bruneton
Browse files
Merge branch 'stsypanov/asm-master'
parents
5495d4d1
edcaba3f
Pipeline
#13422
passed with stage
in 8 minutes and 37 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
asm/src/main/java/org/objectweb/asm/ClassReader.java
View file @
788219ce
...
...
@@ -88,6 +88,9 @@ public class ClassReader {
*/
static
final
int
EXPAND_ASM_INSNS
=
256
;
/** The maximum size of array to allocate. */
private
static
final
int
MAX_BUFFER_SIZE
=
1024
*
1024
;
/** The size of the temporary byte array used to read class input streams chunk by chunk. */
private
static
final
int
INPUT_STREAM_DATA_CHUNK_SIZE
=
4096
;
...
...
@@ -310,13 +313,19 @@ public class ClassReader {
if
(
inputStream
==
null
)
{
throw
new
IOException
(
"Class not found"
);
}
int
bufferSize
=
calculateBufferSize
(
inputStream
);
try
(
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
())
{
byte
[]
data
=
new
byte
[
INPUT_STREAM_DATA_CHUNK_SIZE
];
byte
[]
data
=
new
byte
[
bufferSize
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
data
,
0
,
data
.
length
))
!=
-
1
)
{
int
readCount
=
0
;
while
((
bytesRead
=
inputStream
.
read
(
data
,
0
,
bufferSize
))
!=
-
1
)
{
outputStream
.
write
(
data
,
0
,
bytesRead
);
readCount
++;
}
outputStream
.
flush
();
if
(
readCount
==
1
)
{
return
data
;
}
return
outputStream
.
toByteArray
();
}
finally
{
if
(
close
)
{
...
...
@@ -325,6 +334,20 @@ public class ClassReader {
}
}
private
static
int
calculateBufferSize
(
final
InputStream
inputStream
)
throws
IOException
{
int
expectedLength
=
inputStream
.
available
();
/*
* Some implementations can return 0 while holding available data
* (e.g. new FileInputStream("/proc/a_file"))
* Also in some pathological cases a very small number might be returned,
* and in this case we use default size
*/
if
(
expectedLength
<
256
)
{
return
INPUT_STREAM_DATA_CHUNK_SIZE
;
}
return
Math
.
min
(
expectedLength
,
MAX_BUFFER_SIZE
);
}
// -----------------------------------------------------------------------------------------------
// Accessors
// -----------------------------------------------------------------------------------------------
...
...
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