Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void descargaArchivo(Archivo archivo, String rutaDestino) {
- alfrescoConnector = AlfrescoConnector.getInstance();
- alfrescoConnector.setExternalServerURL(urlBase);
- alfrescoConnector.setServerHost(alfrescoHost);
- alfrescoConnector.setServerPort(alfrescoPort);
- alfrescoConnector.setServerURL(urlBase);
- try {
- String rutaDescarga = "/Company Home/" + archivo.getRutaAlfresco();
- log.info("ruta descarga: " + rutaDescarga);
- AlfrescoNode node = alfrescoConnector.getNode(user, password, rutaDescarga);
- String rutaWebav = getRutaWebdav(node);
- log.info("rutaWebav: " + rutaWebav);
- URLConnection uc = new java.net.URL(rutaWebav).openConnection();
- String encoding = new String(org.bouncycastle.util.encoders.Base64.encode((user + ":" + password).getBytes()));
- uc.setRequestProperty("Authorization", "Basic " + encoding);
- int contentLength = uc.getContentLength();
- java.io.BufferedInputStream in = new java.io.BufferedInputStream(uc.getInputStream());
- byte data[] = new byte[contentLength];
- int offset = 0;
- int bRead;
- while (offset < contentLength) {
- if ((bRead = in.read(data, offset, data.length - offset)) == -1) {
- break;
- }
- offset += bRead;
- }
- in.close();
- FileOutputStream out = new FileOutputStream(rutaDestino + archivo.getNombre());
- out.write(data);
- out.flush();
- out.close();
- } catch (MalformedURLException ex) {
- throw new RuntimeException("URL malformado ", ex);
- } catch (IOException ex) {
- throw new RuntimeException("Error al abrir archivo", ex);
- } catch (Exception ex) {
- throw new RuntimeException("Error al descargar archivo", ex);
- }
- }
Add Comment
Please, Sign In to add comment