]> git.argeo.org Git - gpl/argeo-jcr.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/transfer/ChecksumFailureException.java
Move Argeo SLC JCR components to Argeo JCR
[gpl/argeo-jcr.git] / org.argeo.slc.repo / src / org / eclipse / aether / transfer / ChecksumFailureException.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether.transfer;
12
13 import org.eclipse.aether.RepositoryException;
14
15 /**
16 * Thrown in case of a checksum failure during an artifact/metadata download.
17 */
18 public class ChecksumFailureException
19 extends RepositoryException
20 {
21
22 private final String expected;
23
24 private final String actual;
25
26 private final boolean retryWorthy;
27
28 /**
29 * Creates a new exception with the specified expected and actual checksum. The resulting exception is
30 * {@link #isRetryWorthy() retry-worthy}.
31 *
32 * @param expected The expected checksum as declared by the hosting repository, may be {@code null}.
33 * @param actual The actual checksum as computed from the local bytes, may be {@code null}.
34 */
35 public ChecksumFailureException( String expected, String actual )
36 {
37 super( "Checksum validation failed, expected " + expected + " but is " + actual );
38 this.expected = expected;
39 this.actual = actual;
40 retryWorthy = true;
41 }
42
43 /**
44 * Creates a new exception with the specified detail message. The resulting exception is not
45 * {@link #isRetryWorthy() retry-worthy}.
46 *
47 * @param message The detail message, may be {@code null}.
48 */
49 public ChecksumFailureException( String message )
50 {
51 this( false, message, null );
52 }
53
54 /**
55 * Creates a new exception with the specified cause. The resulting exception is not {@link #isRetryWorthy()
56 * retry-worthy}.
57 *
58 * @param cause The exception that caused this one, may be {@code null}.
59 */
60 public ChecksumFailureException( Throwable cause )
61 {
62 this( "Checksum validation failed" + getMessage( ": ", cause ), cause );
63 }
64
65 /**
66 * Creates a new exception with the specified detail message and cause. The resulting exception is not
67 * {@link #isRetryWorthy() retry-worthy}.
68 *
69 * @param message The detail message, may be {@code null}.
70 * @param cause The exception that caused this one, may be {@code null}.
71 */
72 public ChecksumFailureException( String message, Throwable cause )
73 {
74 this( false, message, cause );
75 }
76
77 /**
78 * Creates a new exception with the specified retry flag, detail message and cause.
79 *
80 * @param retryWorthy {@code true} if the exception is retry-worthy, {@code false} otherwise.
81 * @param message The detail message, may be {@code null}.
82 * @param cause The exception that caused this one, may be {@code null}.
83 */
84 public ChecksumFailureException( boolean retryWorthy, String message, Throwable cause )
85 {
86 super( message, cause );
87 expected = actual = "";
88 this.retryWorthy = retryWorthy;
89 }
90
91 /**
92 * Gets the expected checksum for the downloaded artifact/metadata.
93 *
94 * @return The expected checksum as declared by the hosting repository or {@code null} if unknown.
95 */
96 public String getExpected()
97 {
98 return expected;
99 }
100
101 /**
102 * Gets the actual checksum for the downloaded artifact/metadata.
103 *
104 * @return The actual checksum as computed from the local bytes or {@code null} if unknown.
105 */
106 public String getActual()
107 {
108 return actual;
109 }
110
111 /**
112 * Indicates whether the corresponding download is retry-worthy.
113 *
114 * @return {@code true} if retrying the download might solve the checksum failure, {@code false} if the checksum
115 * failure is non-recoverable.
116 */
117 public boolean isRetryWorthy()
118 {
119 return retryWorthy;
120 }
121
122 }