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