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.AtomicBoolean
closed
-
Fields inherited from interface org.eclipse.aether.spi.connector.transport.Transporter
ERROR_NOT_FOUND, ERROR_OTHER
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTransporter()
Enables subclassing.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this transporter and frees any network resources associated with it.private static void
copy(java.io.OutputStream os, java.io.InputStream is, TransportListener listener)
private void
failIfClosed(TransportTask task)
void
get(GetTask task)
Downloads a resource from the repository.protected abstract void
implClose()
Implementsclose()
, gets only called if the transporter has not already been closed.protected abstract void
implGet(GetTask task)
Implementsget(GetTask)
, gets only called if the transporter has not been closed.protected abstract void
implPeek(PeekTask task)
Implementspeek(PeekTask)
, gets only called if the transporter has not been closed.protected abstract void
implPut(PutTask task)
Implementsput(PutTask)
, gets only called if the transporter has not been closed.void
peek(PeekTask task)
Checks the existence of a resource in the repository.void
put(PutTask task)
Uploads a resource to the repository.protected void
utilGet(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 void
utilPut(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:Transporter
Checks 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:
peek
in 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:Transporter
Downloads 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:
get
in 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
-true
if the supplied input stream should be automatically closed,false
to leave the stream open.length
- The size in bytes of the downloaded resource or-1
if unknown, not to be confused with the length of the supplied input stream which might be smaller if the download is resumed.resume
-true
if the download resumes fromGetTask.getResumeOffset()
,false
if 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:Transporter
Uploads a resource to the repository.- Specified by:
put
in 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
-true
if the supplied output stream should be automatically closed,false
to 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:Transporter
Closes 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 aIllegalStateException
or similar. Closing an already closed transporter is harmless and has no effect.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in 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.IOException
TransferCancelledException
-
-