访存现有资产

请参阅:

要从服务器检索资产,首先需要 com.ibm.ram.client.RAMAsset 对象。此对象表示资产的元数据。可通过此对象使用 getContents() 方法以 RAS 文件的形式获取该资产。

有几种方法可用来从服务器访存资产。要访存资产,请直接使用 RAMSession.getAsset(AssetIdentification) 来按 GUID 和版本检索资产。可使用通配符“*”来访存与模式相匹配的最高版本(请参阅对资产进行版本控制)。
                // Fetch an asset by GUID and version (this just pulls down the asset's metadata)
                RAMAsset asset = session.getAsset(new AssetIdentification("{AC0D54C1-E349-69EC-030F-E51CB557B0D7}", "7.1"));
一旦具有资产,就可以通过 getter 方法和 setter 方法来获取/设置属性。例如:
                // Verify the asset's metadata
                assertEquals("RAM Client API Javadoc", asset.getName());
                assertEquals("Javadoc for the Rational Asset Manager Client API", asset.getDescription());
                assertEquals("Documentation", asset.getAssetType().getName());
                assertEquals("RAM Development", asset.getCommunity().getName());
                assertEquals("Kevin Jones", asset.getOwners()[0].getName());
要以 RAS 文件的形式下载资产,请使用 getContents() 方法:
                // Download the content as a .ras file
                ZipInputStream in = null;
                File file = null;
                FileOutputStream output = null;
                byte[] buffer = new byte[100000];
                try {
                        file = new File("D:\\temp\\newAsset.ras"); //$NON-NLS-1$
                        output = new FileOutputStream(file);
                        in = new ZipInputStream(asset.getContents());

                        int read;
                        int start = 0;
                        while ((read = in.read(buffer, start, buffer.length - start)) > -1) {
                                start += read;
                                if (start >= buffer.length) {
                                        output.write(buffer);
                                        start = 0;
                                }
                        }
                        if (start > 0)
                                output.write(buffer, 0, start);
                } finally {
                        try {
                                if (in != null)
                                        in.close();
                        } catch (IOException e) {
                        }
                        try {
                                if (output != null)
                                        output.close();
                        } catch (IOException e) {
                        }
                }

反馈