05-16-2007 02:57 AM
byte[] result = null;
if (inputStream.available() > 0)
{
result = new byte[inputStream.available()];
inputStream.read(result);;
}
return result;
bytes = new byte[z];
in = wdr.getMethodData();
int x=0;
while(in.available() > 0)
{
in.read(bytes, x*8192, in.available());
x++;
}
You must know the file length to create the array. I'm using WEBDAV. My code:
public byte[] getKBDocument(String sDocumentDMId, String sSolutionDMId)
{
Store store = null; //almacen
Reference reference = null; //reference
String[] sDirs = null; //path directories
String sPath = null; //Alfresco path
String sFinalPath = ""; //webdav path
byte[] bytes = null;
Node node = null;
InputStream in = null;
store = new Store(Constants.WORKSPACE_STORE, STORE);
try
{
AuthenticationUtils.startSession(USER, PASS);
logger.info("getKBDocument");
node = searchNode(store, sDocumentDMId);
reference = node.getReference();
//Get path
sPath = reference.getPath();
logger.info("getKBDocument: Alfresco Path: "+sPath);
sPath = sPath.replace("cm:", "");
sPath = sPath.replace("_x0020_", " ");
sPath = sPath.replace("_x003", "");
sPath = sPath.replace("_", "");
sDirs = sPath.split("/");
for (int i=3; i < sDirs.length; i++)
sFinalPath = sFinalPath+"/"+sDirs[i];
HttpURL hrl = new HttpURL(WEBDAV+ROOT_NODE+sFinalPath);
logger.info("getKBDocument: WEBDAV Path: "+WEBDAV+ROOT_NODE+sFinalPath);
hrl.setUserinfo("admin","admin");
WebdavResource wdr = new WebdavResource(hrl);
int z = (int)wdr.getGetContentLength();
bytes = new byte[z];
in = wdr.getMethodData();
int x=0;
while(in.available() > 0)
{
in.read(bytes, x*8192, in.available());
x++;
}
wdr.close();
}
catch(MalformedURLException mue)
{
System.out.println(mue.getMessage());
//mue.printStackTrace();
//throw new DocumentManagementExceotion();
}
catch(HttpException he)
{
System.out.println(he.getMessage());
//he.printStackTrace();
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
//ioe.printStackTrace();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
return bytes;
}
private Node searchNode(Store store, String uuid) throws Exception{
Node[] nodes = null; //all nodes
Node myNode = null; //node found
Reference reference = null; //reference
Predicate predicate = null; //predicateç
RepositoryServiceSoapBindingStub repositoryService = null; //repository
logger.info("searchNode");
repositoryService = WebServiceFactory.getRepositoryService();
reference = new Reference(store, uuid, null);
predicate = new Predicate(new Reference[]{reference}, null, null);
try {
nodes = repositoryService.get(predicate);
// Obtenemos el nodo.
myNode = nodes[0];
//System.out.println("hola:"+myNode.getReference().getUuid());
} catch (RepositoryFault e) {
System.out.println(ERROR_MANAGER+ " Data not found");
}
logger.info("searchNode node"+myNode.toString());
logger.info("searchNode exit");
return myNode;
}
06-07-2007 11:49 AM
09-05-2007 05:09 AM
12-20-2007 10:42 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.