Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Read only first 8 bytes of class in JavaClassfileVersion #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.codehaus.plexus.languages.java.version;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -62,9 +63,19 @@ public static JavaClassfileVersion of(byte[] bytes) {
* @return the {@link JavaClassfileVersion} of the path java class
*/
public static JavaClassfileVersion of(Path path) {
try {
byte[] readAllBytes = Files.readAllBytes(path);
return of(readAllBytes);
try (InputStream is = Files.newInputStream(path)) {
byte[] bytes = new byte[8];
int total = 0;
while (total < 8) {
int l = is.read(bytes, total, 8 - total);
if (l > 0) {
total += l;
}
if (l == -1) {
break;
}
}
return of(bytes);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
Expand Down