既存のアセットの取り出し

以下を参照してください。

アセットをサーバーから取得するには、まず 、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) {
                        }
                }

フィードバック