@@ -220,10 +220,43 @@ public InputStream downloadArtifactsFile(Integer projectId, String ref, String j
220220 * @param projectId The ID of the project owned by the authenticated user
221221 * @param jobId The unique job identifier
222222 * @param artifactPath Path to a file inside the artifacts archive
223- * @return an InputStream to read the specified artifacts file from
223+ * @param directory the File instance of the directory to save the file to, if null will use "java.io.tmpdir"
224+ * @return a File instance pointing to the download of the specified artifacts file
224225 * @throws GitLabApiException if any exception occurs
225226 */
227+ public File downloadSingleArtifactsFile (Integer projectId , Integer jobId , Path artifactPath , File directory ) throws GitLabApiException {
228+
229+ Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "jobs" , jobId , "artifacts" , artifactPath );
230+ try {
231+
232+ if (directory == null )
233+ directory = new File (System .getProperty ("java.io.tmpdir" ));
226234
235+ String filename = artifactPath .getFileName ().toString ();
236+ File file = new File (directory , filename );
237+
238+ InputStream in = response .readEntity (InputStream .class );
239+ Files .copy (in , file .toPath (), StandardCopyOption .REPLACE_EXISTING );
240+ return (file );
241+
242+ } catch (IOException ioe ) {
243+ throw new GitLabApiException (ioe );
244+ }
245+ }
246+
247+ /**
248+ * Download a single artifact file from within the job's artifacts archive.
249+ *
250+ * Only a single file is going to be extracted from the archive and streamed to a client.
251+ *
252+ * GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
253+ *
254+ * @param projectId The ID of the project owned by the authenticated user
255+ * @param jobId The unique job identifier
256+ * @param artifactPath Path to a file inside the artifacts archive
257+ * @return an InputStream to read the specified artifacts file from
258+ * @throws GitLabApiException if any exception occurs
259+ */
227260 public InputStream downloadSingleArtifactsFile (Integer projectId , Integer jobId , Path artifactPath ) throws GitLabApiException {
228261 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" , projectId , "jobs" , jobId , "artifacts" , artifactPath );
229262 return (response .readEntity (InputStream .class ));
0 commit comments