/** * Method to match <code>ClientListEntry</code> objects based on * whether they the regular expression provided when the object is * instantiated. * * @param entry The <code>ClientListEntry</code> to match. * @return <code>true</code> if <code>ClientListEntry</code>'s filename * matches the pattern, <code>false</code> otherwise. */ public boolean match(ClientListEntry entry) { if (this.pattern != null && this.patternString != null) { File file = new File(entry.getUri().getPath()); Matcher matcher = pattern.matcher(file.getName()); return (matcher.matches()) ? true : false; } return false; }
/** * By default case sensitive and based on US ASCII characters * * @param patternString * @param fileList * @return List of ClientListEntries */ public ArrayList<ClientListEntry> matchFiles(String patternString, ArrayList<ClientListEntry> fileList) { ArrayList<ClientListEntry> filteredList = new ArrayList<ClientListEntry>(); Pattern pattern = Pattern.compile(patternString); for (ClientListEntry fileEntry : fileList) { File file = new File(fileEntry.getUri().getPath()); Matcher matcher = pattern.matcher(file.getName()); if (matcher.matches()) { filteredList.add(fileEntry); } } return filteredList; }
/** * Get the Mapped record that is a representation of the file * * @param entry A wrapper that holds the information we need to get the file * @return The BaseFileTransferMappedRecord representing the file * @throws ResourceException failure to perform get */ protected BaseFileTransferMappedRecord getFile(ClientListEntry entry) throws ResourceException { if(logger.isDebugEnabled()) { // logger.debug("getFile called with: [" + entry + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Getting file [" + entry.getUri().getPath() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().get(entry); } catch (ClientCommandGetException e) { logger.warn("Underlying File Transfer operation failed [GET]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
/** * Get the content from the file as an InputStream * * @param entry - the file * @return content as an InputStream * @throws ResourceException when downloding a file gails */ protected InputStream getContentAsStream(ClientListEntry entry) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Getting content from [" + entry.getUri().getPath() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().getContentAsStream(entry); } catch (ClientCommandGetException e) { logger.warn("Underlying File Transfer operation failed [GET]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
public BaseFileTransferMappedRecord get(ClientListEntry clientListEntry) throws ClientCommandGetException { // Construct file path and get the file into an // BaseFileTransferMappedRecord URI uri = clientListEntry.getUri(); File srcFile = new File((uri).getPath()); logger.debug("Getting file [" + srcFile.getPath() + "] into an BaseFileTransferMappedRecord"); //$NON-NLS-1$ //$NON-NLS-2$ // Getting the file content ByteArrayOutputStream output = new ByteArrayOutputStream(); String fileName = srcFile.getName(); BaseFileTransferMappedRecord record = null; try { if(!this.ftpClient.retrieveFile(fileName, output)) { throw new ClientCommandGetException("Failed to get file [" + fileName //$NON-NLS-1$ + "] from directory [" + uri.getPath()); //$NON-NLS-1$ } record = BaseFileTransferUtils.createBaseFileTransferMappedRecord(uri, output); output.close(); } catch (IOException e) { throw new ClientCommandGetException("Failed to get file [" + fileName //$NON-NLS-1$ + "] from directory [" + uri.getPath(), e); //$NON-NLS-1$ } return record; }
public BaseFileTransferMappedRecord get(ClientListEntry clientListEntry) throws ClientCommandGetException { // Construct file path and get the file into an // BaseFileTransferMappedRecord URI uri = clientListEntry.getUri(); File srcFile = new File((uri).getPath()); logger.debug("Getting file [" + srcFile.getPath() + "] into an BaseFileTransferMappedRecord"); //$NON-NLS-1$ //$NON-NLS-2$ // Getting the file content ByteArrayOutputStream output = new ByteArrayOutputStream(); String fileName = srcFile.getName(); BaseFileTransferMappedRecord record = null; try { if(!this.ftpClient.retrieveFile(fileName, output)) { throw new ClientCommandGetException("Failed to get file [" + fileName //$NON-NLS-1$ + "] from directory [" + uri.getPath()); //$NON-NLS-1$ } record = BaseFileTransferUtils.createBaseFileTransferMappedRecord(uri, output); output.close(); } catch (IOException e) { throw new ClientCommandGetException("Failed to get file [" + fileName //$NON-NLS-1$ + "] from directory [" + uri.getPath(), e); //$NON-NLS-1$ } return record; }
@Override protected ExecutionOutput performExecute() throws ResourceException { logger.info("execute called on this command: [" + this + "]"); //$NON-NLS-1$ //$NON-NLS-2$ ClientListEntry entry = (ClientListEntry) executionContext.get(ExecutionContext.RETRIEVABLE_FILE_PARAM); this.sourcePath = entry.getUri().getPath(); File file = new File(entry.getUri().getPath()); try { String directory = file.getParent() + "/"; chunker.chunkFile(directory, file.getName(), chunkSize); } catch (ChunkException e) { throw new ResourceException("Exception caught whilst trying to chunk", e); //$NON-NLS-1$ } FileChunkHeader fileChunkHeader = ((ChunkerImpl) chunker).getFileChunkHeader(); clientId = (String) executionContext.get(ExecutionContext.CLIENT_ID); entry.setClientId(clientId); dao.persistClientListEntry(entry); return new ExecutionOutput(fileChunkHeader); }
File srcFile = new File((entry.getUri()).getPath()); StringBuilder sb = new StringBuilder(384); sb.append("Trying to get data from file ["); //$NON-NLS-1$
URI uri = entry.getUri();
/** * (non-Javadoc) * @see org.ikasan.connector.basefiletransfer.outbound.command.AbstractBaseFileTransferTransactionalResourceCommand#performExecute() */ @Override protected ExecutionOutput performExecute() throws ResourceException { logger.info("execute called on this command: [" + this + "]"); //$NON-NLS-1$ //$NON-NLS-2$ ClientListEntry entry = (ClientListEntry) executionContext.get(ExecutionContext.RETRIEVABLE_FILE_PARAM); //sourcePath = entry.getUri().getPath(); // We change the path to be file based as opposed to URI based, // means that root starts as '/' as opposed to '//' which // some FTP servers don't like String uriPath = entry.getUri().getPath(); File path = new File(uriPath); sourcePath = path.getPath(); BaseFileTransferMappedRecord record = getFile(entry); String clientId = (String) executionContext.get(ExecutionContext.CLIENT_ID); logger.debug("got clientId [" + clientId + "]"); //$NON-NLS-1$ //$NON-NLS-2$ entry.setClientId(clientId); dao.persistClientListEntry(entry); return new ExecutionOutput(record); }
public InputStream getContentAsStream(ClientListEntry entry) throws ClientCommandGetException File srcFile = new File((entry.getUri()).getPath()); logger.debug("Trying to get data from file [" + srcFile.getPath() + "] into an InputStream"); //$NON-NLS-1$ //$NON-NLS-2$ InputStream input = null;
public InputStream getContentAsStream(ClientListEntry entry) throws ClientCommandGetException File srcFile = new File((entry.getUri()).getPath()); logger.debug("Trying to get data from file [" + srcFile.getPath() + "] into an InputStream"); //$NON-NLS-1$ //$NON-NLS-2$ InputStream input = null;
int dUri = this.uri.compareTo(e.getUri()); int dLastModified = this.dtLastModified.compareTo(e.getDtLastModified()); int dLastAccessed = this.dtLastAccessed.compareTo(e.getDtLastAccessed());
for (ClientListEntry entry : entryList) String filePath = entry.getUri().getPath(); if (entry.isDirectory())
String sourcePath = entry.getUri().getPath(); executionContext.put(ExecutionContext.PAYLOAD, result); logger.debug("About to call ChecksumValidatorCommand"); //$NON-NLS-1$
for (ClientListEntry entry : entryList) String filePath = entry.getUri().getPath(); if(entry.isDirectory())
for (ClientListEntry entry : entryList) String filePath = entry.getUri().getPath(); if(entry.isDirectory())
String sourcePath = entry.getUri().getPath(); executionContext.put(ExecutionContext.PAYLOAD, result); logger.debug("About to call ChecksumValidatorCommand"); //$NON-NLS-1$