]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/transfer/TransferResource.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.transfer
;
15 import org
.eclipse
.aether
.RequestTrace
;
18 * Describes a resource being uploaded or downloaded by the repository system.
20 public final class TransferResource
23 private final String repositoryUrl
;
25 private final String resourceName
;
27 private final File file
;
29 private final long startTime
;
31 private final RequestTrace trace
;
33 private long contentLength
= -1;
35 private long resumeOffset
;
38 * Creates a new transfer resource with the specified properties.
40 * @param repositoryUrl The base URL of the repository, may be {@code null} or empty if unknown. If not empty, a
41 * trailing slash will automatically be added if missing.
42 * @param resourceName The relative path to the resource within the repository, may be {@code null}. A leading slash
43 * (if any) will be automatically removed.
44 * @param file The source/target file involved in the transfer, may be {@code null}.
45 * @param trace The trace information, may be {@code null}.
47 public TransferResource( String repositoryUrl
, String resourceName
, File file
, RequestTrace trace
)
49 if ( repositoryUrl
== null || repositoryUrl
.length() <= 0 )
51 this.repositoryUrl
= "";
53 else if ( repositoryUrl
.endsWith( "/" ) )
55 this.repositoryUrl
= repositoryUrl
;
59 this.repositoryUrl
= repositoryUrl
+ '/';
62 if ( resourceName
== null || resourceName
.length() <= 0 )
64 this.resourceName
= "";
66 else if ( resourceName
.startsWith( "/" ) )
68 this.resourceName
= resourceName
.substring( 1 );
72 this.resourceName
= resourceName
;
79 startTime
= System
.currentTimeMillis();
83 * The base URL of the repository, e.g. "http://repo1.maven.org/maven2/". Unless the URL is unknown, it will be
84 * terminated by a trailing slash.
86 * @return The base URL of the repository or an empty string if unknown, never {@code null}.
88 public String
getRepositoryUrl()
94 * The path of the resource relative to the repository's base URL, e.g. "org/apache/maven/maven/3.0/maven-3.0.pom".
96 * @return The path of the resource, never {@code null}.
98 public String
getResourceName()
104 * Gets the local file being uploaded or downloaded. When the repository system merely checks for the existence of a
105 * remote resource, no local file will be involved in the transfer.
107 * @return The source/target file involved in the transfer or {@code null} if none.
109 public File
getFile()
115 * The size of the resource in bytes. Note that the size of a resource during downloads might be unknown to the
116 * client which is usually the case when transfers employ compression like gzip. In general, the content length is
117 * not known until the transfer has {@link TransferListener#transferStarted(TransferEvent) started}.
119 * @return The size of the resource in bytes or a negative value if unknown.
121 public long getContentLength()
123 return contentLength
;
127 * Sets the size of the resource in bytes.
129 * @param contentLength The size of the resource in bytes or a negative value if unknown.
130 * @return This resource for chaining, never {@code null}.
132 public TransferResource
setContentLength( long contentLength
)
134 this.contentLength
= contentLength
;
139 * Gets the byte offset within the resource from which the download starts. A positive offset indicates a previous
140 * download attempt is being resumed, {@code 0} means the transfer starts at the first byte.
142 * @return The zero-based index of the first byte being transferred, never negative.
144 public long getResumeOffset()
150 * Sets the byte offset within the resource at which the download starts.
152 * @param resumeOffset The zero-based index of the first byte being transferred, must not be negative.
153 * @return This resource for chaining, never {@code null}.
155 public TransferResource
setResumeOffset( long resumeOffset
)
157 if ( resumeOffset
< 0 )
159 throw new IllegalArgumentException( "resume offset cannot be negative" );
161 this.resumeOffset
= resumeOffset
;
166 * Gets the timestamp when the transfer of this resource was started.
168 * @return The timestamp when the transfer of this resource was started.
170 public long getTransferStartTime()
176 * Gets the trace information that describes the higher level request/operation during which this resource is
179 * @return The trace information about the higher level operation or {@code null} if none.
181 public RequestTrace
getTrace()
187 public String
toString()
189 return getRepositoryUrl() + getResourceName() + " <> " + getFile();