001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.spi.connector; 020 021import java.io.File; 022 023import org.eclipse.aether.metadata.Metadata; 024import org.eclipse.aether.transfer.MetadataTransferException; 025 026/** 027 * A download/upload of metadata. 028 * 029 * @noextend This class is not intended to be extended by clients. 030 */ 031public abstract class MetadataTransfer extends Transfer { 032 033 private Metadata metadata; 034 035 private File file; 036 037 private MetadataTransferException exception; 038 039 MetadataTransfer() { 040 // hide 041 } 042 043 /** 044 * Gets the metadata being transferred. 045 * 046 * @return The metadata being transferred or {@code null} if not set. 047 */ 048 public Metadata getMetadata() { 049 return metadata; 050 } 051 052 /** 053 * Sets the metadata to transfer. 054 * 055 * @param metadata The metadata, may be {@code null}. 056 * @return This transfer for chaining, never {@code null}. 057 */ 058 public MetadataTransfer setMetadata(Metadata metadata) { 059 this.metadata = metadata; 060 return this; 061 } 062 063 /** 064 * Gets the local file the metadata is downloaded to or uploaded from. In case of a download, a connector should 065 * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is 066 * completed such that an interrupted/failed download does not corrupt the current file contents. 067 * 068 * @return The local file or {@code null} if not set. 069 */ 070 public File getFile() { 071 return file; 072 } 073 074 /** 075 * Sets the local file the metadata is downloaded to or uploaded from. 076 * 077 * @param file The local file, may be {@code null}. 078 * @return This transfer for chaining, never {@code null}. 079 */ 080 public MetadataTransfer setFile(File file) { 081 this.file = file; 082 return this; 083 } 084 085 /** 086 * Gets the exception that occurred during the transfer (if any). 087 * 088 * @return The exception or {@code null} if the transfer was successful. 089 */ 090 public MetadataTransferException getException() { 091 return exception; 092 } 093 094 /** 095 * Sets the exception that occurred during the transfer. 096 * 097 * @param exception The exception, may be {@code null} to denote a successful transfer. 098 * @return This transfer for chaining, never {@code null}. 099 */ 100 public MetadataTransfer setException(MetadataTransferException exception) { 101 this.exception = exception; 102 return this; 103 } 104}