1 package org.eclipse.aether.transfer; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.eclipse.aether.RepositoryException; 23 24 /** 25 * Thrown in case of a checksum failure during an artifact/metadata download. 26 */ 27 public class ChecksumFailureException 28 extends RepositoryException 29 { 30 31 private final String expected; 32 33 private final String actual; 34 35 private final boolean retryWorthy; 36 37 /** 38 * Creates a new exception with the specified expected and actual checksum. The resulting exception is 39 * {@link #isRetryWorthy() retry-worthy}. 40 * 41 * @param expected The expected checksum as declared by the hosting repository, may be {@code null}. 42 * @param actual The actual checksum as computed from the local bytes, may be {@code null}. 43 */ 44 public ChecksumFailureException( String expected, String actual ) 45 { 46 super( "Checksum validation failed, expected " + expected + " but is " + actual ); 47 this.expected = expected; 48 this.actual = actual; 49 retryWorthy = true; 50 } 51 52 /** 53 * Creates a new exception with the specified detail message. The resulting exception is not 54 * {@link #isRetryWorthy() retry-worthy}. 55 * 56 * @param message The detail message, may be {@code null}. 57 */ 58 public ChecksumFailureException( String message ) 59 { 60 this( false, message, null ); 61 } 62 63 /** 64 * Creates a new exception with the specified cause. The resulting exception is not {@link #isRetryWorthy() 65 * retry-worthy}. 66 * 67 * @param cause The exception that caused this one, may be {@code null}. 68 */ 69 public ChecksumFailureException( Throwable cause ) 70 { 71 this( "Checksum validation failed" + getMessage( ": ", cause ), cause ); 72 } 73 74 /** 75 * Creates a new exception with the specified detail message and cause. The resulting exception is not 76 * {@link #isRetryWorthy() retry-worthy}. 77 * 78 * @param message The detail message, may be {@code null}. 79 * @param cause The exception that caused this one, may be {@code null}. 80 */ 81 public ChecksumFailureException( String message, Throwable cause ) 82 { 83 this( false, message, cause ); 84 } 85 86 /** 87 * Creates a new exception with the specified retry flag, detail message and cause. 88 * 89 * @param retryWorthy {@code true} if the exception is retry-worthy, {@code false} otherwise. 90 * @param message The detail message, may be {@code null}. 91 * @param cause The exception that caused this one, may be {@code null}. 92 */ 93 public ChecksumFailureException( boolean retryWorthy, String message, Throwable cause ) 94 { 95 super( message, cause ); 96 expected = actual = ""; 97 this.retryWorthy = retryWorthy; 98 } 99 100 /** 101 * Gets the expected checksum for the downloaded artifact/metadata. 102 * 103 * @return The expected checksum as declared by the hosting repository or {@code null} if unknown. 104 */ 105 public String getExpected() 106 { 107 return expected; 108 } 109 110 /** 111 * Gets the actual checksum for the downloaded artifact/metadata. 112 * 113 * @return The actual checksum as computed from the local bytes or {@code null} if unknown. 114 */ 115 public String getActual() 116 { 117 return actual; 118 } 119 120 /** 121 * Indicates whether the corresponding download is retry-worthy. 122 * 123 * @return {@code true} if retrying the download might solve the checksum failure, {@code false} if the checksum 124 * failure is non-recoverable. 125 */ 126 public boolean isRetryWorthy() 127 { 128 return retryWorthy; 129 } 130 131 }