Class AbstractTransporter
- java.lang.Object
-
- org.eclipse.aether.spi.connector.transport.AbstractTransporter
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Transporter
public abstract class AbstractTransporter extends java.lang.Object implements Transporter
A skeleton implementation for custom transporters.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleanclosed-
Fields inherited from interface org.eclipse.aether.spi.connector.transport.Transporter
ERROR_NOT_FOUND, ERROR_OTHER
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTransporter()Enables subclassing.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this transporter and frees any network resources associated with it.private static voidcopy(java.io.OutputStream os, java.io.InputStream is, TransportListener listener)private voidfailIfClosed(TransportTask task)voidget(GetTask task)Downloads a resource from the repository.protected abstract voidimplClose()Implementsclose(), gets only called if the transporter has not already been closed.protected abstract voidimplGet(GetTask task)Implementsget(GetTask), gets only called if the transporter has not been closed.protected abstract voidimplPeek(PeekTask task)Implementspeek(PeekTask), gets only called if the transporter has not been closed.protected abstract voidimplPut(PutTask task)Implementsput(PutTask), gets only called if the transporter has not been closed.voidpeek(PeekTask task)Checks the existence of a resource in the repository.voidput(PutTask task)Uploads a resource to the repository.protected voidutilGet(GetTask task, java.io.InputStream is, boolean close, long length, boolean resume)Performs stream-based I/O for the specified download task and notifies the configured transport listener.protected voidutilPut(PutTask task, java.io.OutputStream os, boolean close)Performs stream-based I/O for the specified upload task and notifies the configured transport listener.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.aether.spi.connector.transport.Transporter
classify
-
-
-
-
Method Detail
-
peek
public void peek(PeekTask task) throws java.lang.Exception
Description copied from interface:TransporterChecks the existence of a resource in the repository. If the remote repository can be contacted successfully but indicates the resource specified in the request does not exist, an exception is thrown such that invokingTransporter.classify(Throwable)with that exception yieldsTransporter.ERROR_NOT_FOUND.- Specified by:
peekin interfaceTransporter- Parameters:
task- The existence check to perform, must not benull.- Throws:
java.lang.Exception- If the existence of the specified resource could not be confirmed.
-
implPeek
protected abstract void implPeek(PeekTask task) throws java.lang.Exception
Implementspeek(PeekTask), gets only called if the transporter has not been closed.- Parameters:
task- The existence check to perform, must not benull.- Throws:
java.lang.Exception- If the existence of the specified resource could not be confirmed.
-
get
public void get(GetTask task) throws java.lang.Exception
Description copied from interface:TransporterDownloads a resource from the repository. If the resource is downloaded to a file as given byGetTask.getDataFile()and the operation fails midway, the transporter should not delete the partial file but leave its management to the caller.- Specified by:
getin interfaceTransporter- Parameters:
task- The download to perform, must not benull.- Throws:
java.lang.Exception- If the transfer failed.
-
implGet
protected abstract void implGet(GetTask task) throws java.lang.Exception
Implementsget(GetTask), gets only called if the transporter has not been closed.- Parameters:
task- The download to perform, must not benull.- Throws:
java.lang.Exception- If the transfer failed.
-
utilGet
protected void utilGet(GetTask task, java.io.InputStream is, boolean close, long length, boolean resume) throws java.io.IOException, TransferCancelledException
Performs stream-based I/O for the specified download task and notifies the configured transport listener. Subclasses might want to invoke this utility method from within theirimplGet(GetTask)to avoid boilerplate I/O code.- Parameters:
task- The download to perform, must not benull.is- The input stream to download the data from, must not benull.close-trueif the supplied input stream should be automatically closed,falseto leave the stream open.length- The size in bytes of the downloaded resource or-1if unknown, not to be confused with the length of the supplied input stream which might be smaller if the download is resumed.resume-trueif the download resumes fromGetTask.getResumeOffset(),falseif the download starts at the first byte of the resource.- Throws:
java.io.IOException- If the transfer encountered an I/O error.TransferCancelledException- If the transfer was cancelled.
-
put
public void put(PutTask task) throws java.lang.Exception
Description copied from interface:TransporterUploads a resource to the repository.- Specified by:
putin interfaceTransporter- Parameters:
task- The upload to perform, must not benull.- Throws:
java.lang.Exception- If the transfer failed.
-
implPut
protected abstract void implPut(PutTask task) throws java.lang.Exception
Implementsput(PutTask), gets only called if the transporter has not been closed.- Parameters:
task- The upload to perform, must not benull.- Throws:
java.lang.Exception- If the transfer failed.
-
utilPut
protected void utilPut(PutTask task, java.io.OutputStream os, boolean close) throws java.io.IOException, TransferCancelledException
Performs stream-based I/O for the specified upload task and notifies the configured transport listener. Subclasses might want to invoke this utility method from within theirimplPut(PutTask)to avoid boilerplate I/O code.- Parameters:
task- The upload to perform, must not benull.os- The output stream to upload the data to, must not benull.close-trueif the supplied output stream should be automatically closed,falseto leave the stream open.- Throws:
java.io.IOException- If the transfer encountered an I/O error.TransferCancelledException- If the transfer was cancelled.
-
close
public void close()
Description copied from interface:TransporterCloses this transporter and frees any network resources associated with it. Once closed, a transporter must not be used for further transfers, any attempt to do so would yield aIllegalStateExceptionor similar. Closing an already closed transporter is harmless and has no effect.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceTransporter
-
implClose
protected abstract void implClose()
Implementsclose(), gets only called if the transporter has not already been closed.
-
failIfClosed
private void failIfClosed(TransportTask task)
-
copy
private static void copy(java.io.OutputStream os, java.io.InputStream is, TransportListener listener) throws java.io.IOException, TransferCancelledException- Throws:
java.io.IOExceptionTransferCancelledException
-
-