--- title: "Java SDK" slug: "storage-storage-10-13" tags: ["Classic", "VPC", "Archive Storage"] updated: 2026-10-22T09:07:57Z published: 2026-10-22T09:07:57Z canonical: "guide-gov.ncloud-docs.com/storage-storage-10-13" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide-gov.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Java SDK Classic/VPC 환경에서 이용 가능합니다. openstack4j 라이브러리를 이용하여 네이버 클라우드 플랫폼의 Archive Storage를 사용하는 예제입니다. 이 가이드에서는 openstack4j 3.1.0 버전을 기준으로 안내합니다. 참고 openstack4j 3.1.0 버전의 관련 문서는 다음과 같습니다. - [OpenStack4j 문서](https://openstack4j.github.io/learn/) ## 설치 SDK를 설치하는 방법은 다음과 같습니다. 라이브러리를 직접 다운로드하거나 Apache Maven으로 설치할 수 있습니다. - 라이브러리 다운로드: [openstack4j 3.1.0 버전 다운로드](https://search.maven.org/remotecontent?filepath=org/pacesys/openstack4j/3.1.0/openstack4j-3.1.0.jar) - Apache Maven으로 설치 ``` org.pacesys openstack4j 3.1.0 ``` ## 인증 이 가이드의 모든 예제는 `OSClientV3` 객체를 사용합니다. `OSClientV3` 객체는 인증 정보를 기반으로 생성된 `Token` 객체를 이용해 생성됩니다. 토큰이 만료되거나 유효하지 않은 경우 자동으로 갱신되며, 멀티스레드 환경에서는 하나의 토큰 객체를 공유하여 불필요한 인증 절차를 줄일 수 있습니다. 참고 예제에 사용된 `ACCESS_KEY_ID`, `SECRET_KEY`, `DOMAIN_ID`, `PROJECT_ID`는 네이버 클라우드 플랫폼에서 발급받은 API 인증키와 인증 정보 값입니다. 해당 값을 확인하는 방법은 [서비스 연동](/docs/archivestorage-integration)을 참조해 주십시오. ``` final String endpoint = "https://kr.archive.gov-ncloudstorage.com:5000/v3"; final String user = "ACCESS_KEY_ID"; final String password = "SECRET_KEY"; final String domainId = "DOMAIN_ID"; final String projectId = "PROJECT_ID"; Token token = OSFactory.builderV3() .endpoint(endpoint) .credentials(user, password, Identifier.byId(domainId)) .scopeToProject(Identifier.byId(projectId), Identifier.byId(domainId)) .authenticate() .getToken(); OSClientV3 client = OSFactory.clientFromToken(token); ``` ``` // Spawn off a thread giving it the access myThreadExecutor.submit(new MyRunnableOrCallable(token)); // Example of the Runnable or other object invoked in a new thread public class MyRunnable implements Runnable { private OSClientV3 client; public MyRunnable(Access access) { client = OSFactory.clientFromToken(token); } public void run() { // can now use the client :) } } ``` ## 예제 Java SDK를 이용하여 Archive Storage를 사용하는 방법을 설명합니다. ### 컨테이너(버킷) 목록 조회 컨테이너(버킷) 목록을 조회하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageContainerService containerService = client.objectStorage().containers(); List containers = containerService.list(ContainerListOptions.create().limit(100)); for (SwiftContainer container : containers) { System.out.println(container); } ``` ### 컨테이너(버킷) 생성 컨테이너(버킷)를 생성하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageContainerService containerService = client.objectStorage().containers(); String containerName = "sample-container"; // with metadata // X-Container-Meta-Test-Meta-Key: test-meta-value Map metadata = new HashMap<>(); metadata.put("test-meta-key", "test-meta-value"); ActionResponse response = containerService.create(containerName, CreateUpdateContainerOptions.create().metadata(metadata)); System.out.println(response); ``` ### 컨테이너(버킷) 삭제 컨테이너(버킷)를 삭제하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageContainerService containerService = client.objectStorage().containers(); String containerName = "sample-container"; ActionResponse response = containerService.delete(containerName); System.out.println(response); ``` ### 오브젝트 업로드 오브젝트를 업로드하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-object.txt"; String contentType = "text/plain"; File file = new File("/tmp/sample-object.txt"); // with metadata // X-Object-Meta-Test-Meta-Key : test-meta-value Map metadata = new HashMap<>(); metadata.put("test-meta-key", "test-meta-value"); String etag = objectService.put(containerName, objectName, Payloads.create(file), ObjectPutOptions.create().contentType(contentType).metadata(metadata)); System.out.println(etag); ``` ### 디렉토리 오브젝트 생성 디렉터리 오브젝트를 생성하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageContainerService containerService = client.objectStorage().containers(); String containerName = "sample-container"; String directoryName = "sample-directory"; String etag = containerService.createPath(containerName, directoryName); System.out.println(etag); ``` ### 오브젝트 목록 조회 오브젝트 목록을 조회하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String directoryName = "sample-directory"; // simple List objects = objectService.list(containerName); for (SwiftObject object : objects) { System.out.println(object); } // list for directory List objectsForDirectory = objectService.list(containerName, ObjectListOptions.create().path(directoryName)); for (SwiftObject object : objectsForDirectory) { System.out.println(object); } ``` ### 오브젝트 다운로드 오브젝트를 다운로드하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-object.txt"; String downloadPath = "/tmp/sample-object.txt"; DLPayload payload = objectService.download(containerName, objectName); File file = new File(downloadPath); payload.writeToFile(file); ``` ### 오브젝트 삭제 오브젝트를 삭제하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-object.txt"; ActionResponse response = objectService.delete(containerName, objectName); System.out.println(response); ``` ### 대용량 파일 업로드(SLO) SLO 방식을 사용하여 대용량 파일을 업로드하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(getToken()); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-big-file.mp4"; String contentType = "video/mp4"; String segmentContainerName = "segment-container"; String segmentPrefix = "segments-for-sample-big-file.mp4/segment-"; List> segmentInfoList = new ArrayList<>(); File file = new File("/tmp/sample.mp4"); FileInputStream fs = new FileInputStream(file); int bufferSize = 1024 * 1024 * 10; // 10MB byte[] buffer = new byte[bufferSize]; int segmentNo = 1; int bytesRead; while ((bytesRead = fs.read(buffer)) != -1) { Map segmentInfo = new HashMap<>(); InputStreamPayload payload = new InputStreamPayload(new ByteArrayInputStream(buffer, 0, bytesRead)); String etag = objectService.put(segmentContainerName, segmentPrefix + segmentNo, payload); segmentInfo.put("path", "/" + segmentContainerName + "/" + segmentPrefix + segmentNo); segmentInfo.put("etag", etag); segmentInfo.put("size_bytes", bytesRead); segmentInfoList.add(segmentInfo); segmentNo++; } fs.close(); String manifest = new ObjectMapper().writeValueAsString(segmentInfoList); String etag = objectService.put(containerName, objectName, Payloads.create(new ByteArrayInputStream(manifest.getBytes())), ObjectPutOptions.create().queryParam("multipart-manifest", "put").contentType(contentType)); System.out.println(etag); ``` ### 대용량 파일 세그먼트 조회(SLO) 대용량 파일의 세그먼트 목록을 조회하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-big-file.mp4"; ObjectListOptions options = ObjectListOptions.create(); options.getOptions().put("multipart-manifest", "get"); List objects = objectService.list(containerName + "/" + objectName, options); for (SwiftObject object : objects) { System.out.println(object); } ``` ### 대용량 파일 삭제(SLO) 대용량 파일을 삭제하는 예시는 다음과 같습니다. ``` OSClientV3 client = OSFactory.clientFromToken(token); ObjectStorageObjectService objectService = client.objectStorage().objects(); String containerName = "sample-container"; String objectName = "sample-big-file.mp4"; ActionResponse response = objectService.delete(ObjectLocation.create(containerName, objectName), ObjectDeleteOptions.create().queryParam("multipart-manifest", "delete")); System.out.println(response); ```