11package land .oras ;
22
3- import java .io .InputStream ;
4- import java .io .IOException ;
53import java .io .BufferedInputStream ;
64import java .io .ByteArrayInputStream ;
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
77import java .io .OutputStream ;
88import java .net .URI ;
99import java .nio .file .Files ;
@@ -223,13 +223,14 @@ public Manifest pushArtifact(
223223 public void pullArtifact (ContainerRef containerRef , Path path , boolean overwrite ) {
224224 Manifest manifest = getManifest (containerRef );
225225 for (Layer layer : manifest .getLayers ()) {
226- Path targetPath = path . resolve ( layer . getAnnotations ()
227- .getOrDefault (Const .ANNOTATION_TITLE , layer .getDigest ()));
228-
226+ Path targetPath =
227+ path . resolve ( layer . getAnnotations () .getOrDefault (Const .ANNOTATION_TITLE , layer .getDigest ()));
228+
229229 try (InputStream is = fetchBlob (containerRef .withDigest (layer .getDigest ()))) {
230- Files .copy (is , targetPath , overwrite ?
231- StandardCopyOption .REPLACE_EXISTING :
232- StandardCopyOption .ATOMIC_MOVE );
230+ Files .copy (
231+ is ,
232+ targetPath ,
233+ overwrite ? StandardCopyOption .REPLACE_EXISTING : StandardCopyOption .ATOMIC_MOVE );
233234 } catch (IOException e ) {
234235 throw new OrasException ("Failed to pull artifact" , e );
235236 }
@@ -272,9 +273,10 @@ public Manifest pushArtifact(
272273 Layer layer = pushBlobStream (containerRef , is , size )
273274 .withMediaType (Const .DEFAULT_BLOB_DIR_MEDIA_TYPE ) // Use tar+gzip for directories
274275 .withAnnotations (Map .of (
275- Const .ANNOTATION_TITLE , path .getFileName ().toString (),
276- Const .ANNOTATION_ORAS_UNPACK , "true"
277- ));
276+ Const .ANNOTATION_TITLE ,
277+ path .getFileName ().toString (),
278+ Const .ANNOTATION_ORAS_UNPACK ,
279+ "true" ));
278280 layers .add (layer );
279281 LOG .info ("Uploaded directory: {}" , layer .getDigest ());
280282 }
@@ -290,8 +292,8 @@ public Manifest pushArtifact(
290292 Layer layer = pushBlobStream (containerRef , is , size )
291293 .withMediaType (mediaType )
292294 .withAnnotations (Map .of (
293- Const .ANNOTATION_TITLE , path . getFileName (). toString ()
294- ));
295+ Const .ANNOTATION_TITLE ,
296+ path . getFileName (). toString () ));
295297 layers .add (layer );
296298 LOG .info ("Uploaded: {}" , layer .getDigest ());
297299 }
@@ -669,8 +671,9 @@ public Layer pushBlobStream(ContainerRef containerRef, InputStream input, long s
669671 // Copy input stream to temp file while calculating digest
670672 String digest ;
671673 try (InputStream bufferedInput = new BufferedInputStream (input );
672- DigestInputStream digestInput = new DigestInputStream (bufferedInput , MessageDigest .getInstance ("SHA-256" ));
673- OutputStream fileOutput = Files .newOutputStream (tempFile )) {
674+ DigestInputStream digestInput =
675+ new DigestInputStream (bufferedInput , MessageDigest .getInstance ("SHA-256" ));
676+ OutputStream fileOutput = Files .newOutputStream (tempFile )) {
674677
675678 digestInput .transferTo (fileOutput );
676679 byte [] digestBytes = digestInput .getMessageDigest ().digest ();
@@ -692,7 +695,10 @@ public Layer pushBlobStream(ContainerRef containerRef, InputStream input, long s
692695
693696 // Start with a POST request to initiate the upload
694697 OrasHttpClient .ResponseWrapper <String > initiateResponse = client .uploadStream (
695- "POST" , baseUri , emptyStream , 0 ,
698+ "POST" ,
699+ baseUri ,
700+ emptyStream ,
701+ 0 ,
696702 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ));
697703
698704 if (initiateResponse .statusCode () != 202 ) {
@@ -717,12 +723,15 @@ public Layer pushBlobStream(ContainerRef containerRef, InputStream input, long s
717723 // Upload the content from the temporary file
718724 try (InputStream uploadStream = Files .newInputStream (tempFile )) {
719725 OrasHttpClient .ResponseWrapper <String > uploadResponse = client .uploadStream (
720- "PUT" , finalizeUri , uploadStream , size ,
726+ "PUT" ,
727+ finalizeUri ,
728+ uploadStream ,
729+ size ,
721730 Map .of (Const .CONTENT_TYPE_HEADER , Const .APPLICATION_OCTET_STREAM_HEADER_VALUE ));
722731
723732 if (uploadResponse .statusCode () != 201 && uploadResponse .statusCode () != 202 ) {
724- throw new OrasException ("Failed to upload blob: " + uploadResponse .statusCode () +
725- " - Response: " + uploadResponse .response ());
733+ throw new OrasException ("Failed to upload blob: " + uploadResponse .statusCode () + " - Response: "
734+ + uploadResponse .response ());
726735 }
727736
728737 return Layer .fromDigest (digest , size );
0 commit comments