336 /**
337 * Returns the maximum version used when searching for versioned entries.
338 *
339 * @return the maximum version
340 * @since 9
341 */
342 public final Runtime.Version getVersion() {
343 return isMultiRelease() ? this.version : BASE_VERSION;
344 }
345
346 /**
347 * Indicates whether or not this jar file is a multi-release jar file.
348 *
349 * @return true if this JarFile is a multi-release jar file
350 * @since 9
351 */
352 public final boolean isMultiRelease() {
353 if (isMultiRelease) {
354 return true;
355 }
356 if (MULTI_RELEASE_ENABLED && versionMajor != BASE_VERSION_MAJOR) {
357 try {
358 checkForSpecialAttributes();
359 } catch (IOException io) {
360 isMultiRelease = false;
361 }
362 }
363 return isMultiRelease;
364 }
365
366 /**
367 * Returns the jar file manifest, or {@code null} if none.
368 *
369 * @return the jar file manifest, or {@code null} if none
370 *
371 * @throws IllegalStateException
372 * may be thrown if the jar file has been closed
373 * @throws IOException if an I/O error has occurred
374 */
375 public Manifest getManifest() throws IOException {
376 return getManifestFromReference();
943 }
944
945 /**
946 * On first invocation, check if the JAR file has the Class-Path
947 * and the Multi-Release attribute. A no-op on subsequent calls.
948 */
949 private void checkForSpecialAttributes() throws IOException {
950 if (hasCheckedSpecialAttributes) {
951 return;
952 }
953 synchronized (this) {
954 if (hasCheckedSpecialAttributes) {
955 return;
956 }
957 JarEntry manEntry = getManEntry();
958 if (manEntry != null) {
959 byte[] b = getBytes(manEntry);
960 hasClassPathAttribute = match(CLASSPATH_CHARS, b,
961 CLASSPATH_LASTOCC) != -1;
962 // is this a multi-release jar file
963 if (MULTI_RELEASE_ENABLED && versionMajor != BASE_VERSION_MAJOR) {
964 int i = match(MULTIRELEASE_CHARS, b, MULTIRELEASE_LASTOCC);
965 if (i != -1) {
966 i += MULTIRELEASE_CHARS.length;
967 if (i < b.length) {
968 byte c = b[i++];
969 // Check that the value is followed by a newline
970 // and does not have a continuation
971 if (c == '\n' &&
972 (i == b.length || b[i] != ' ')) {
973 isMultiRelease = true;
974 } else if (c == '\r') {
975 if (i == b.length) {
976 isMultiRelease = true;
977 } else {
978 c = b[i++];
979 if (c == '\n') {
980 if (i == b.length || b[i] != ' ') {
981 isMultiRelease = true;
982 }
983 } else if (c != ' ') {
|
336 /**
337 * Returns the maximum version used when searching for versioned entries.
338 *
339 * @return the maximum version
340 * @since 9
341 */
342 public final Runtime.Version getVersion() {
343 return isMultiRelease() ? this.version : BASE_VERSION;
344 }
345
346 /**
347 * Indicates whether or not this jar file is a multi-release jar file.
348 *
349 * @return true if this JarFile is a multi-release jar file
350 * @since 9
351 */
352 public final boolean isMultiRelease() {
353 if (isMultiRelease) {
354 return true;
355 }
356 if (MULTI_RELEASE_ENABLED) {
357 try {
358 checkForSpecialAttributes();
359 } catch (IOException io) {
360 isMultiRelease = false;
361 }
362 }
363 return isMultiRelease;
364 }
365
366 /**
367 * Returns the jar file manifest, or {@code null} if none.
368 *
369 * @return the jar file manifest, or {@code null} if none
370 *
371 * @throws IllegalStateException
372 * may be thrown if the jar file has been closed
373 * @throws IOException if an I/O error has occurred
374 */
375 public Manifest getManifest() throws IOException {
376 return getManifestFromReference();
943 }
944
945 /**
946 * On first invocation, check if the JAR file has the Class-Path
947 * and the Multi-Release attribute. A no-op on subsequent calls.
948 */
949 private void checkForSpecialAttributes() throws IOException {
950 if (hasCheckedSpecialAttributes) {
951 return;
952 }
953 synchronized (this) {
954 if (hasCheckedSpecialAttributes) {
955 return;
956 }
957 JarEntry manEntry = getManEntry();
958 if (manEntry != null) {
959 byte[] b = getBytes(manEntry);
960 hasClassPathAttribute = match(CLASSPATH_CHARS, b,
961 CLASSPATH_LASTOCC) != -1;
962 // is this a multi-release jar file
963 if (MULTI_RELEASE_ENABLED) {
964 int i = match(MULTIRELEASE_CHARS, b, MULTIRELEASE_LASTOCC);
965 if (i != -1) {
966 i += MULTIRELEASE_CHARS.length;
967 if (i < b.length) {
968 byte c = b[i++];
969 // Check that the value is followed by a newline
970 // and does not have a continuation
971 if (c == '\n' &&
972 (i == b.length || b[i] != ' ')) {
973 isMultiRelease = true;
974 } else if (c == '\r') {
975 if (i == b.length) {
976 isMultiRelease = true;
977 } else {
978 c = b[i++];
979 if (c == '\n') {
980 if (i == b.length || b[i] != ' ') {
981 isMultiRelease = true;
982 }
983 } else if (c != ' ') {
|