List of usage examples for java.nio.file Files newDirectoryStream
public static DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException
From source file:org.codice.ddf.catalog.plugin.metacard.backup.storage.filestorage.MetacardBackupFileStorage.java
private boolean isDirectoryEmpty(Path dir) throws IOException { try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir)) { return !dirStream.iterator().hasNext(); } catch (IOException e) { LOGGER.debug("Unable to open directory stream for {}", dir.toString(), e); throw e;/*www . jav a2 s .c o m*/ } }
From source file:io.BiojavaReader.java
private static boolean isDirEmpty(final Path directory) throws IOException { try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory)) { return !dirStream.iterator().hasNext(); }//from ww w . j a v a 2 s . c o m }
From source file:org.fim.internal.StateGenerator.java
private void scanFileTree(BlockingDeque<Path> filesToHashQueue, Path directory, FimIgnore parentFimIgnore) throws NoSuchAlgorithmException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { FimIgnore fimIgnore = fimIgnoreManager.loadLocalIgnore(directory, parentFimIgnore); for (Path file : stream) { if (!fileHashersStarted && filesToHashQueue.size() > FILES_QUEUE_CAPACITY / 2) { startFileHashers();//from w w w . ja va 2 s. c o m } BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); String fileName = file.getFileName().toString(); if (fimIgnoreManager.isIgnored(fileName, attributes, fimIgnore)) { fimIgnoreManager.ignoreThisFiles(file, attributes); } else { if (attributes.isRegularFile()) { enqueueFile(filesToHashQueue, file); } else if (attributes.isDirectory()) { scanFileTree(filesToHashQueue, file, fimIgnore); } } } } catch (IOException ex) { Console.newLine(); Logger.error("Skipping - Error scanning directory '" + directory + "'", ex, context.isDisplayStackTrace()); } }
From source file:au.org.ands.vocabs.toolkit.provider.transform.JsonTreeTransformProvider.java
@Override public final boolean transform(final TaskInfo taskInfo, final JsonNode subtask, final HashMap<String, String> results) { Path dir = Paths.get(ToolkitFileUtils.getTaskHarvestOutputPath(taskInfo)); ConceptHandler conceptHandler = new ConceptHandler(); // Parse all input files in the harvest directory, loading // the content into conceptHandler. try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { RDFFormat format = Rio.getParserFormatForFileName(entry.toString()); RDFParser rdfParser = Rio.createParser(format); rdfParser.setRDFHandler(conceptHandler); FileInputStream is = new FileInputStream(entry.toString()); rdfParser.parse(is, entry.toString()); logger.debug("Reading RDF: " + entry.toString()); }// ww w . ja va2 s . co m } catch (DirectoryIteratorException | IOException | RDFParseException | RDFHandlerException | UnsupportedRDFormatException ex) { results.put(TaskStatus.EXCEPTION, "Exception in JsonTreeTransform while Parsing RDF"); logger.error("Exception in JsonTreeTransform while Parsing RDF:", ex); return false; } // Extract the result, save in results Set and store in the // file system. String resultFileNameTree = ToolkitFileUtils.getTaskOutputPath(taskInfo, "concepts_tree.json"); try { Set<Concept> conceptTree = conceptHandler.buildForest(); // Future work: either (a) make the returned JSON not // just an array, but an object in which the concept tree // is the value of one key/value pair, and the // other key/value pairs are this sort of diagnostic information, // or (b) return an array as usual, if everything is OK, // or a string containing diagnostic information if // something went wrong. // For now, generate a JSON tree _only_ if there are only // tree edges. if (conceptHandler.isOnlyTreeEdges()) { // Serialize the tree and write to the file system. // Jackson will serialize TreeSets in sorted order of values // (i.e., the Concept objects' prefLabels). File out = new File(resultFileNameTree); results.put("concepts_tree", resultFileNameTree); FileUtils.writeStringToFile(out, TaskUtils.collectionToJSONString(conceptTree)); } else { String reason; if (conceptHandler.isCycle()) { // In giving a reason, cycles take priority. reason = "there is a cycle"; } else { reason = "there is a forward or cross edge"; } results.put("concepts_tree_not_provided", "No concepts tree " + "provided, because " + reason + "."); logger.error("JsonTreeTransform: not providing a concept " + "tree because " + reason + "."); // Future work: // write something else, e.g., a JSON string. // FileUtils.writeStringToFile(out, "something"); } } catch (IOException ex) { results.put(TaskStatus.EXCEPTION, "IO exception in JsonTreeTransform while " + "generating result"); logger.error("IO exception in JsonTreeTransform generating result:", ex); return false; } catch (Exception ex) { // Any other possible cause? results.put(TaskStatus.EXCEPTION, "Exception in JsonTreeTransform while generating result"); logger.error("Exception in JsonTreeTransform generating result:", ex); return false; } return true; }
From source file:org.cryptomator.ui.InitializeController.java
private boolean isDirectoryEmpty() { try {//from www. ja v a 2 s. co m final DirectoryStream<Path> dirContents = Files.newDirectoryStream(directory.getPath()); return !dirContents.iterator().hasNext(); } catch (IOException e) { LOG.error("Failed to analyze directory.", e); throw new IllegalStateException(e); } }
From source file:org.jacoco.examples.ReportGenerator.java
private List<File> getFileNames(List<File> fileNames, Path dir) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path path : stream) { if (path.toFile().isDirectory()) { getFileNames(fileNames, path); } else { boolean match = false; for (String pattern : regexes) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); if (matcher.matches(path)) { match = true;/*from www . ja v a 2 s. co m*/ break; } } if (!match) { fileNames.add(path.toFile()); } } } } catch ( IOException e) { e.printStackTrace(); } return fileNames; }
From source file:de.bayern.gdi.model.DownloadStepConverterIT.java
/** * Test to execute./*from ww w.ja v a 2 s . c o m*/ * * @throws Exception if an exception occured */ @Test public void testConvert() throws Exception { LOG.debug("Start test '{}' in test directory: {}", testName, downloadStep.getPath()); DownloadStepConverter downloadStepConverter = new DownloadStepConverter(); JobList jobList = downloadStepConverter.convert(downloadStep); FileDownloadJob fileDownloadJob = findFileDownloadJob(jobList); assertThat(fileDownloadJob, is(notNullValue())); fileDownloadJob.download(); String downloadPath = downloadStep.getPath(); Path path = Paths.get(downloadPath); DirectoryStream<Path> paths = Files.newDirectoryStream(path); Iterator<Path> iterator = paths.iterator(); assertThat(iterator.hasNext(), is(true)); }
From source file:fr.afcepf.atod.wine.data.parser.XmlParser.java
public static void main(String[] args) { log.info("\t ### debut du test ###"); /*URL url;/*w w w .ja v a2s . c o m*/ try { url = new URL(apiBaseUrl+"/categorymap?filter=categories(490)&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/ategoryMap.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/categoryMap.xml"); FileUtils.copyURLToFile(url, file); } //100 vins rouges fr au dela de 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+124)+price(100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/RedWines100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/RedWines100.xml"); FileUtils.copyURLToFile(url, file); } //100 vins rouges fr entre 50 et 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+124)+price(50|100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/RedWines50-100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/RedWines50-100.xml"); FileUtils.copyURLToFile(url, file); } //100 vins rouges fr entre 10 et 50 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+124)+price(10|50)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/RedWines10-50.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/RedWines10-50.xml"); FileUtils.copyURLToFile(url, file); } //100 vins blancs fr au dela de 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+125)+price(100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/WhiteWines100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/WhiteWines100.xml"); FileUtils.copyURLToFile(url, file); } //100 vins blancs fr entre 50 et 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+125)+price(50|100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/WhiteWines50-100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/WhiteWines50-100.xml"); FileUtils.copyURLToFile(url, file); } //100 vins blancs fr entre 10 et 50 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+125)+price(10|50)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/WhiteWines10-50.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/WhiteWines10-50.xml"); FileUtils.copyURLToFile(url, file); } //100 champagnes fr au dela de 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+123)+price(100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/ChampagneWines100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/ChampagneWines100.xml"); FileUtils.copyURLToFile(url, file); } //100 champagnes fr entre 50 et 100 url = new URL(apiBaseUrl+"/catalog?filter=categories(490+123)+price(50|100)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/ChampagneWines50-100.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/ChampagneWines50-100.xml"); FileUtils.copyURLToFile(url, file); } //100 vins ross fr url = new URL(apiBaseUrl+"/catalog?filter=categories(490+126)&size=100&search=France&apikey="+apikey); if(Files.exists(Paths.get(getResourcePath() + "FilesXML/Wines/RoseWines10-50.xml"))==false){ File file = new File(getResourcePath() + "FilesXML/Wines/RoseWines10-50.xml"); FileUtils.copyURLToFile(url, file); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ Locale.setDefault(Locale.US); BeanFactory bf2 = new AnnotationConfigApplicationContext(ElasticsearchConfiguration.class); WineService esRepository = (WineService) bf2.getBean(WineService.class); esRepository.deleteIdx(); BeanFactory bf = new ClassPathXmlApplicationContext("classpath:springData.xml"); IDaoProduct daoVin = (IDaoProduct) bf.getBean(IDaoProduct.class); IDaoSupplier daoSupplier = (IDaoSupplier) bf.getBean(IDaoSupplier.class); IDaoAdmin daoAdmin = bf.getBean(IDaoAdmin.class); IDaoSpecialEvent daoEvent = bf.getBean(IDaoSpecialEvent.class); IDaoCountry daoCountry = bf.getBean(IDaoCountry.class); IDaoCustomer daoCustomer = bf.getBean(IDaoCustomer.class); IDaoShippingMethode daoShippingMethod = bf.getBean(IDaoShippingMethode.class); IDaoPaymentInfo daoPayment = bf.getBean(IDaoPaymentInfo.class); IDaoProductFeature daoFeature = (IDaoProductFeature) bf.getBean(IDaoProductFeature.class); try { daoCountry .insertObj(new Country(null, "AT", "Autriche", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry .insertObj(new Country(null, "BE", "Belgique", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry .insertObj(new Country(null, "BG", "Bulgarie", "BGN", "Lev Bulgare", "flaticon-bulgaria-lev")); daoCountry.insertObj(new Country(null, "CY", "Chypre", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "CZ", "Rpublique Tchque", "CZK", "Couronne tchque", "flaticon-czech-republic-koruna-currency-symbol")); daoCountry.insertObj( new Country(null, "DE", "Allemagne", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "DK", "Danemark", "DKK", "Couronne danoise", "flaticon-denmark-krone-currency-symbol")); daoCountry.insertObj(new Country(null, "EE", "Estonie", "EEK", "Couronne estonienne", "flaticon-estonia-kroon-currency-symbol")); daoCountry .insertObj(new Country(null, "ES", "Espagne", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry .insertObj(new Country(null, "FI", "Finlande", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "GB", "Royaume-Uni", "GBP", "Livre sterling", "flaticon-pound-symbol-variant")); daoCountry.insertObj(new Country(null, "GR", "Grce", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "HU", "Hongrie", "HUF", "Forint hongrois", "flaticon-hungary-forint-currency-symbol")); daoCountry .insertObj(new Country(null, "IE", "Irlande", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "IT", "Italie", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj( new Country(null, "JP", "Japon", "JPY", "Yen japonais", "flaticon-yen-currency-symbol")); daoCountry.insertObj(new Country(null, "LT", "Lituanie", "LTL", "Litas lituanien", "flaticon-lithuania-litas-currency-symbol")); daoCountry.insertObj( new Country(null, "LU", "Luxembourg", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "LV", "Lettonie", "LVL", "Lats letton", "flaticon-latvia-lat")); daoCountry.insertObj(new Country(null, "MT", "Malte", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry .insertObj(new Country(null, "NL", "Pays-Bas", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "PL", "Pologne", "PLN", "Zloty polonais", "flaticon-poland-zloty-currency-symbol")); daoCountry .insertObj(new Country(null, "PT", "Portugal", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry .insertObj(new Country(null, "RO", "Roumanie", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "SE", "Sude", "SEK", "Couronne sudoise", "flaticon-sweden-krona-currency-symbol")); daoCountry.insertObj( new Country(null, "SI", "Slovnie", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj( new Country(null, "SK", "Slovaquie", "EUR", "Euro", "flaticon-euro-currency-symbol")); daoCountry.insertObj(new Country(null, "US", "Etats-Unis", "USD", "Dollar U.S.", "flaticon-dollar-currency-symbol-2")); daoCountry.insertObj(new Country(null, "FR", "France", "EUR", "Euro", "flaticon-euro-currency-symbol")); } catch (WineException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } Admin admin = null; Customer customer1 = null; Customer customer2 = null; Customer customer3 = null; try { admin = new Admin(null, "strateur", "admini", new Date(), "nicolastorero@gmail.com", "nicolastorero@gmail.com", "test1234", "0680413240", new Date(), new Date(), Civility.MR); customer1 = new Customer(null, "Wang", "Fen", new Date(), "fenwang@hotmail.com", "fenwang@hotmail.com", "test1234", "0666666666", new Date(), new Date(), Civility.MISS, true); customer2 = new Customer(null, "Anes", "Zouheir", new Date(), "zouheir.anes@gmail.com", "zouheir.anes@gmail.com", "test1234", "0666666666", new Date(), new Date(), Civility.MR, true); customer3 = new Customer(null, "Storero", "Nicolas", new Date(), "nicolastorero@gmail.com", "nicolastorero@gmail.com", "test1234", "0666666666", new Date(), new Date(), Civility.MR, true); daoAdmin.insertObj(admin); daoShippingMethod.insertObj(new ShippingMethod(null, "Colissimo")); daoPayment.insertObj(new PaymentInfo(null, "Visa")); daoCustomer.insertObj(customer1); daoCustomer.insertObj(customer2); Country c = daoCountry.findObj(29); customer3.addAdress(new Adress(null, "rue de rivoli", "18", "75001", "Paris", c, false)); customer3.addAdress(new Adress(null, "rue de rivoli", "18", "75001", "Paris", c, true)); daoCustomer.updateObj(customer3); } catch (WineException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Product productRand = new Product(null, "pre", 500.0, "un produit"); SpecialEvent se = new SpecialEvent(null, "Promotest", new Date(), new Date(), new Date(), "10% sur une slection de produits", true, admin, 10); Product productAccessorie = new ProductAccessories(null, "un mug", 25.0, "un beau mug", new Date()); Supplier supplier1 = new Supplier(null, "Aux bon vins de Bourgogne", "05 85 74 85 69", "vinsbourgogne@gmail.com", new Date()); Supplier supplier2 = new Supplier(null, "Aux bon vins de Bordeaux", "04 85 74 85 69", "vinsbordeaux@gmail.com", new Date()); Supplier supplier3 = new Supplier(null, "Aux bon vins de l'Aude", "07 85 74 85 69", "vinsaude@gmail.com", new Date()); try { //Les Set sont particulirement adapts pour manipuler une grande //quantit de donnes. Cependant, les performances de ceux-ci peuvent //tre amoindries en insertion. Gnralement, on opte pour un HashSet, //car il est plus performant en temps d'accs ProductSupplier productSuppliers1 = new ProductSupplier(); ProductSupplier productSuppliers2 = new ProductSupplier(); productSuppliers1.setProduct(productRand); productSuppliers1.setSupplier(daoSupplier.insertObj(supplier1)); productSuppliers1.setQuantity(30); productSuppliers2.setProduct(productRand); productSuppliers2.setSupplier(daoSupplier.insertObj(supplier2)); productSuppliers2.setQuantity(15); productRand.getProductSuppliers().add(productSuppliers1); productRand.getProductSuppliers().add(productSuppliers2); daoVin.insertObj(productRand); ProductSupplier productSuppliers3 = new ProductSupplier(); productSuppliers3.setProduct(productAccessorie); productSuppliers3.setSupplier(daoSupplier.insertObj(supplier3)); productSuppliers3.setQuantity(20); productAccessorie.getProductSuppliers().add(productSuppliers3); daoVin.insertObj(productAccessorie); for (Path filepath : Files.newDirectoryStream(Paths.get(getResourcePath() + "FilesXML/Wines/"))) { if (filepath.getFileName().toString().contains("xml")) { list.add(parseSampleXml("FilesXML/Wines/" + filepath.getFileName())); } } } catch (WineException ex) { java.util.logging.Logger.getLogger(XmlParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException e) { java.util.logging.Logger.getLogger(XmlParser.class.getName()).log(Level.SEVERE, null, e); } try { daoEvent.insertObj(se); if (features.isEmpty() == false) { for (ProductFeature pf : features.values()) { daoFeature.insertObj(pf); } } Integer cpt = 0; for (ArrayList<ProductWine> subList : list) { for (ProductWine productWine : subList) { ProductSupplier ps = new ProductSupplier(); ps.setProduct(productWine); ps.setSupplier(supplier1); ps.setQuantity(randomWithRange(1, 50)); productWine.getProductSuppliers().add(ps); if (cpt % 2 == 0) { ProductSupplier ps2 = new ProductSupplier(); ps2.setProduct(productWine); ps2.setSupplier(supplier2); ps2.setQuantity(randomWithRange(1, 50)); productWine.getProductSuppliers().add(ps2); } else if (cpt % 3 == 0) { ProductSupplier ps3 = new ProductSupplier(); ps3.setProduct(productWine); ps3.setSupplier(supplier3); ps3.setQuantity(randomWithRange(1, 50)); productWine.getProductSuppliers().add(ps3); } if (cpt < 11) { productWine.setSpeEvent(se); } daoVin.insertObj(productWine); Wine esWine = new Wine(productWine.getId(), productWine.getName(), productWine.getAppellation(), productWine.getPrice(), productWine.getApiId(), new WineType(productWine.getProductType().getId(), productWine.getProductType().getType()), new WineVintage(((productWine.getProductVintage() != null) ? productWine.getProductVintage().getYear().toString() : "")), new WineVarietal(productWine.getProductVarietal().getId(), productWine.getProductVarietal().getDescription())); for (ProductFeature feat : productWine.getFeatures()) { esWine.addFeature(new WineFeature(feat.getId(), feat.getLabel())); } esRepository.save(esWine); cpt++; } } } catch (WineException paramE) { // TODO Auto-generated catch block paramE.printStackTrace(); } /*BeanFactory bf = new ClassPathXmlApplicationContext("classpath:springData.xml"); IDaoProduct daoVin = (IDaoProduct) bf.getBean(IDaoProduct.class); try { BeanFactory bf = new ClassPathXmlApplicationContext("classpath:springData.xml"); IDaoProduct daoVin = (IDaoProduct) bf.getBean(IDaoProduct.class); List<Product> list = daoVin.findAllObj(); for (Product product : list) { String imagesUrl = ((ProductWine)product).getImagesUrl(); String xmlId = ((ProductWine)product).getApiId().toString(); String [] urls = imagesUrl.split("\\|"); for (int i = 0; i < urls.length; i++) { if(urls[i].trim()!=""){ URL url = new URL(urls[i].trim()); String filename = FilenameUtils.getBaseName(url.toString())+"."+FilenameUtils.getExtension(url.toString()); if(Files.exists(Paths.get(getResourcePath() + "wine_pictures/"+xmlId+"/"+filename))==false){ File file = new File(getResourcePath() + "wine_pictures/"+xmlId+"/"+filename); try { FileUtils.copyURLToFile(url, file); } catch (FileNotFoundException e) { } } if(filename==xmlId+"m.jpg"){ if(Files.exists(Paths.get(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"l.jpg"))==false){ File file = new File(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"l.jpg"); URL url2 = new URL(urls[i].trim().replace("m.jpg", "l.jpg")); try { FileUtils.copyURLToFile(url2, file); } catch (FileNotFoundException e) { } } } } } if(xmlId.length()==6){ URL url = new URL("http://cdn.fluidretail.net/customers/c1477/"+xmlId.substring(0, 2)+"/"+xmlId.substring(2,4)+"/"+xmlId.substring(4)+"/_s/pi/n/"+xmlId+"_spin_spin2/main_variation_na_view_01_204x400.jpg"); if(Files.exists(Paths.get(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"_front.jpg"))==false){ File file = new File(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"_front.jpg"); try { FileUtils.copyURLToFile(url, file); } catch (FileNotFoundException e) { } } URL url2 = new URL("http://cdn.fluidretail.net/customers/c1477/"+xmlId.substring(0, 2)+"/"+xmlId.substring(2,4)+"/"+xmlId.substring(4)+"/_s/pi/n/"+xmlId+"_spin_spin2/main_variation_na_view_07_204x400.jpg"); if(Files.exists(Paths.get(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"_back.jpg"))==false){ File file = new File(getResourcePath() + "wine_pictures/"+xmlId+"/"+xmlId+"_back.jpg"); try { FileUtils.copyURLToFile(url2, file); } catch (FileNotFoundException e) { } } } } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WineException e) { // TODO Auto-generated catch block e.printStackTrace(); } //http://cdn.fluidretail.net/customers/c1477/13/68/80/_s/pi/n/136880_spin_spin2/main_variation_na_view_01_204x400.jpg*/ insert_translations(bf, bf2); log.info("\t ### Fin du test ###"); }
From source file:org.n52.movingcode.runtime.coderepository.LocalVersionedFileRepository.java
/** * Scans the root directory for subfolders and returns them. * In this type of repo, each subfolder SHALL contain a single package. * //from w w w .j a va2s . c om * @param path * @return */ private static final Collection<Path> listSubdirs(Path path) { Collection<Path> dirs = new HashSet<Path>(); DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream(path); for (Path entry : stream) { if (Files.isDirectory(entry)) { dirs.add(entry); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return dirs; }
From source file:de.bbe_consulting.mavento.MagentoInfoMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { initMojo();/* ww w. j ava 2 s . com*/ getLog().info("Scanning: " + magentoPath); getLog().info(""); if (mVersion != null) { getLog().info("Version: Magento " + mVersion.toString()); } // parse sql properties from local.xml final Path localXmlPath = Paths.get(magentoPath + "/app/etc/local.xml"); Document localXml = null; if (Files.exists(localXmlPath)) { localXml = MagentoXmlUtil.readXmlFile(localXmlPath.toAbsolutePath().toString()); } else { throw new MojoExecutionException( "Could not read or parse /app/etc/local.xml." + " Use -DmagentoPath= to set Magento dir."); } final Map<String, String> dbSettings = MagentoXmlUtil.getDbValues(localXml); final String jdbcUrl = MagentoSqlUtil.getJdbcUrl(dbSettings.get("host"), dbSettings.get("port"), dbSettings.get("dbname")); // fetch installdate final String magentoInstallDate = MagentoXmlUtil.getMagentoInstallData(localXml); getLog().info("Installed: " + magentoInstallDate); getLog().info(""); // read baseUrl MagentoCoreConfig baseUrl = null; try { baseUrl = new MagentoCoreConfig("web/unsecure/base_url"); } catch (Exception e) { throw new MojoExecutionException("Error creating config entry. " + e.getMessage(), e); } String sqlError = SQL_CONNECTION_VALID; try { baseUrl = MagentoSqlUtil.getCoreConfigData(baseUrl, dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); getLog().info("URL: " + baseUrl.getValue()); getLog().info(""); } catch (MojoExecutionException e) { sqlError = e.getMessage(); } getLog().info("Database: " + dbSettings.get("dbname") + " via " + dbSettings.get("user") + "@" + dbSettings.get("host") + ":" + dbSettings.get("port")); getLog().info("Connection: " + sqlError); getLog().info(""); if (!skipSize) { MutableLong rootSizeTotal = new MutableLong(); try { FileSizeVisitor fs = new FileSizeVisitor(rootSizeTotal); Files.walkFileTree(Paths.get(magentoPath), fs); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } getLog().info( "Magento files total: " + String.format("%,8d", rootSizeTotal.toLong()).trim() + " bytes"); if (SQL_CONNECTION_VALID.equals(sqlError)) { try { final Map<String, Integer> dbDetails = MagentoSqlUtil.getDbSize(dbSettings.get("dbname"), dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); final List<MysqlTable> logTableDetails = MagentoSqlUtil.getLogTablesSize( dbSettings.get("dbname"), dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); getLog().info("Database total: " + String.format("%,8d", dbDetails.get("totalRows")).trim() + " entries / " + String.format("%,8d", dbDetails.get("totalSize")).trim() + "mb"); int logSizeTotal = 0; int logRowsTotal = 0; for (MysqlTable t : logTableDetails) { logSizeTotal += t.getTableSizeInMb(); logRowsTotal += t.getTableRows(); if (showDetails) { getLog().info(" " + t.getTableName() + ": " + t.getFormatedTableEntries() + " entries / " + t.getFormatedTableSizeInMb() + "mb"); } } getLog().info("Log tables total: " + String.format("%,8d", logRowsTotal).trim() + " entries / " + String.format("%,8d", logSizeTotal).trim() + "mb"); } catch (MojoExecutionException e) { getLog().info("Error: " + e.getMessage()); } } getLog().info(""); } // parse modules final Path modulesXmlPath = Paths.get(magentoPath + "/app/etc/modules"); if (!Files.exists(modulesXmlPath)) { throw new MojoExecutionException("Could not find /app/etc/modules directory."); } DirectoryStream<Path> files = null; final ArrayList<MagentoModule> localModules = new ArrayList<MagentoModule>(); final ArrayList<MagentoModule> communityModules = new ArrayList<MagentoModule>(); try { files = Files.newDirectoryStream(modulesXmlPath); for (Path path : files) { if (!path.getFileName().toString().startsWith("Mage")) { MagentoModule m = new MagentoModule(path); if (m.getCodePool().equals("local")) { localModules.add(m); } else { communityModules.add(m); } } } } catch (IOException e) { throw new MojoExecutionException("Could not read modules directory. " + e.getMessage(), e); } finally { try { files.close(); } catch (IOException e) { throw new MojoExecutionException("Error closing directory stream. " + e.getMessage(), e); } } // print module sorted module list final MagentoModuleComperator mmc = new MagentoModuleComperator(); Collections.sort(localModules, mmc); Collections.sort(communityModules, mmc); getLog().info("Installed modules in.."); getLog().info("..local: "); for (MagentoModule m : localModules) { getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: " + m.isActive()); } if (localModules.size() == 0) { getLog().info("--none--"); } getLog().info(""); getLog().info("..community: "); for (MagentoModule m : communityModules) { getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: " + m.isActive()); } if (communityModules.size() == 0) { getLog().info("--none--"); } getLog().info(""); // check local overlays for content getLog().info("Overlay status.."); int fileCount = -1; final File localMage = new File(magentoPath + "/app/code/local/Mage"); if (localMage.exists()) { fileCount = localMage.list().length; if (fileCount > 0) { getLog().info("local/Mage: " + localMage.list().length + " file(s)"); } } final File localVarien = new File(magentoPath + "/app/code/local/Varien"); if (localVarien.exists()) { fileCount = localVarien.list().length; if (fileCount > 0) { getLog().info("local/Varien: " + localVarien.list().length + " file(s)"); } } if (fileCount == -1) { getLog().info("..not in use."); } }