@Override protected Resource doInBackground() throws Exception { if (!resource.isExists()) { return null; } return resource; }
private Properties loadProperties() throws IOException { final Properties properties = new Properties(); if (!captureStateFile.isExists()) { logger.info("Capture state file does not exist: {}", captureStateFile); return properties; } captureStateFile.read((Action<InputStream>) properties::load); return properties; }
@Validate public void validate() { if (!overwriteFileIfExists && file.isExists()) { throw new IllegalStateException( "The file already exists. Please configure the job to overwrite the existing file."); } }
public boolean isFileFound() { if (_datastore instanceof ResourceDatastore) { Resource resource = ((ResourceDatastore) _datastore).getResource(); if (resource != null) { return resource.isExists(); } } String filename = getFilename(); if (filename == null) { return false; } File file = new File(filename); return file.exists(); }
public DefaultConfigurationReaderInterceptor(final Resource propertiesResource, final DataCleanerEnvironment baseEnvironment) { if (propertiesResource == null || !propertiesResource.isExists()) { _propertyOverrides = Collections.emptyMap(); } else { _propertyOverrides = propertiesResource.read(new InputStreamToPropertiesMapFunc()); } _baseEnvironment = baseEnvironment; }
protected static boolean needsLineBreak(Resource resource, CsvConfiguration configuration) { if (!resource.isExists() || resource.getSize() == 0) { return false;
protected static boolean needsLineBreak(Resource resource, CsvConfiguration configuration) { if (!resource.isExists() || resource.getSize() == 0) { return false;
private InputStream getInputStream(Datastore ds, HttpServletResponse response) throws IOException { if (ds instanceof ResourceDatastore) { final Resource resource = ((ResourceDatastore) ds).getResource(); if (resource == null || !resource.isExists()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Datastore resource not found: " + ds); return null; } String username = getUsername(); logger.info("Serving datastore resource {} to user: {}", resource, username); return resource.read(); } else if (ds instanceof FileDatastore) { final FileDatastore fileDatastore = (FileDatastore) ds; final String filename = fileDatastore.getFilename(); final File file = new File(filename); if (!file.exists() || !file.isFile()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Datastore file not found: " + filename); return null; } String username = getUsername(); logger.info("Serving datastore file {} to user: {}", filename, username); return new FileInputStream(file); } response.sendError(HttpServletResponse.SC_NO_CONTENT, "Datastore is not file based: " + ds.getName()); return null; }
/** * Validates a job before loading it with a concrete datastore. * * @param context * @param job * * @throws FileNotFoundException */ private void preLoadJob(DataCleanerConfiguration configuration, DataCleanerJobContext job) throws FileNotFoundException, ResourceException { final String sourceDatastoreName = job.getSourceDatastoreName(); final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(sourceDatastoreName); if (datastore instanceof ResourceDatastore) { Resource resource = ((ResourceDatastore) datastore).getResource(); if (resource == null || !resource.isExists()) { logger.warn("Raising ResourceException from datastore: {}", datastore); throw new ResourceException(resource, "Resource does not exist: " + resource); } } else if (datastore instanceof FileDatastore) { final String filename = ((FileDatastore) datastore).getFilename(); final File file = new File(filename); if (!file.exists()) { logger.warn("Raising FileNotFound exception from datastore: {}", datastore); throw new FileNotFoundException(filename); } } }
public boolean isDirectory(final URI path) { final Resource resource = getResourceToUse(path); if (!resource.isExists()) { return false; } if (resource instanceof FileResource) { return ((FileResource) resource).getFile().isDirectory(); } if (resource instanceof HdfsResource) { final FileSystem fileSystem = ((HdfsResource) resource).getHadoopFileSystem(); final Path hadoopPath = ((HdfsResource) resource).getHadoopPath(); try { return fileSystem.isDirectory(hadoopPath); } catch (final IOException e) { throw new IllegalStateException(e); } } // actually we don't know, but most likely it's not a directory return false; } }
if (!resource.isExists()) {
if (!resource.isExists()) {
@Override protected CsvSchema getMainSchema() throws MetaModelException { CsvSchema schema = new CsvSchema(getMainSchemaName(), this); if (_resource.isExists()) { schema.setTable(new CsvTable(schema, _resource.getName())); } return schema; }
@Override protected CsvSchema getMainSchema() throws MetaModelException { CsvSchema schema = new CsvSchema(getMainSchemaName(), this); if (_resource.isExists()) { schema.setTable(new CsvTable(schema, _resource.getName())); } return schema; }
public static void copy(Resource from, Resource to) throws IllegalStateException { assert from.isExists(); final InputStream in = from.read(); try { final OutputStream out = to.write(); try { copy(in, out); } finally { safeClose(out); } } finally { safeClose(in); } }
public static void copy(Resource from, Resource to) throws IllegalStateException { assert from.isExists(); final InputStream in = from.read(); try { final OutputStream out = to.write(); try { copy(in, out); } finally { safeClose(out); } } finally { safeClose(in); } }
@Override protected Schema getMainSchema() throws MetaModelException { if (!_resource.isExists()) { logger.info("Resource does not exist, returning empty schema"); return new MutableSchema(getMainSchemaName()); } try { final SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(); final Schema schema = delegate.createSchema(getMainSchemaName()); assert getMainSchemaName().equals(schema.getName()); return schema; } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new MetaModelException("Unexpected exception while building main schema", e); } }
@Override protected Schema getMainSchema() throws MetaModelException { if (!_resource.isExists()) { logger.info("Resource does not exist, returning empty schema"); return new MutableSchema(getMainSchemaName()); } try { final SpreadsheetReaderDelegate delegate = getSpreadsheetReaderDelegate(); final Schema schema = delegate.createSchema(getMainSchemaName()); assert getMainSchemaName().equals(schema.getName()); return schema; } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new MetaModelException("Unexpected exception while building main schema", e); } }