public void parseLogToThingWorx(File file) { DaiCollectionParser parser = new DaiCollectionParser(); Map<String, String> fileMeta = new HashMap<String, String>(); List<DaiMeterCollection> collections = null; DateTime time = new DateTime(); String timezone = time.getZone().toString(); fileMeta.put("olson_timezone_id", timezone); fileMeta.put("current_system_time", String.valueOf(System.currentTimeMillis())); String fileCreated = ""; BasicFileAttributes attributes = null; try { attributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); fileCreated = String.valueOf(attributes.creationTime().toMillis()); } catch (IOException e) { logger.warn("Unable to get File Create Time: ", e.getMessage()); } fileMeta.put("file_create_time", fileCreated); try { collections = parser.parse(file, fileMeta); } catch (Exception e) { logger.warn("Failed to parse file: ", e.getMessage()); } sendToThingWorx(collections); }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { System.out.println("find dir:" + dir.toFile().getName()); System.out.println("attrs:" + attrs); System.out.println(attrs.creationTime().toString()); return FileVisitResult.CONTINUE; }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { System.out.println("find file:" + file.toFile().getName()); System.out.println("attrs:" + attrs); System.out.println(attrs.creationTime().toString()); return FileVisitResult.CONTINUE; }
@Override public void initialize(URL location, ResourceBundle resources) { // TODO Auto-generated method stub this.tbViewColData.setCellValueFactory(cellData -> cellData.getValue().DataProperty()); this.tbViewColArquivo.setCellValueFactory(cellData -> cellData.getValue().FileNameProperty()); File file = new File("./relatorios/"); if (file.exists()) { File[] m = file.listFiles(); for (File f : m) { Path path = FileSystems.getDefault().getPath("./relatorios"); BasicFileAttributes attributes; try { attributes = Files.readAttributes(path, BasicFileAttributes.class); FileTime creationTime = attributes.creationTime(); data.add(new TableHistoricoData(creationTime.toString(), f.getPath())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } this.tbViewHistorico.getItems().addAll(data); } this.tbViewHistorico.setRowFactory( tv -> { TableRow<TableHistoricoData> row = new TableRow<>(); row.setOnMouseClicked( event -> { if (event.getClickCount() == 2 && (!row.isEmpty())) { TableHistoricoData rowData = row.getItem(); try { Thread t = new Thread() { public void run() { if (Desktop.isDesktopSupported()) if (Desktop.getDesktop().isSupported(Action.OPEN)) { Desktop op = Desktop.getDesktop(); if (new File(rowData.getFileName()).exists()) { try { op.open(new File(rowData.getFileName())); } catch (IOException e) { e.printStackTrace(); } } } } }; t.start(); } catch (Exception e) { e.printStackTrace(); } } }); return row; }); }
public FsDir(String aMountPoint, File aFile) { super(aMountPoint, aFile); try { BasicFileAttributes attr = Files.readAttributes(aFile.toPath(), BasicFileAttributes.class); creationDate = attr.creationTime(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public StorageMetadata getContainerMetadata(String container) { MutableStorageMetadata metadata = new MutableStorageMetadataImpl(); metadata.setName(container); metadata.setType(StorageType.CONTAINER); metadata.setLocation(getLocation(container)); Path path = new File(buildPathStartingFromBaseDir(container)).toPath(); BasicFileAttributes attr; try { attr = readAttributes(path, BasicFileAttributes.class); } catch (IOException e) { throw Throwables.propagate(e); } metadata.setCreationDate(new Date(attr.creationTime().toMillis())); return metadata; }
public final void update(File[] xml) { if (xml != null || xml.length != 0) { data = new String[xml.length][columnNames.length]; try { for (int i = 0; i < xml.length; i++) { if (xml[i].isFile()) { BasicFileAttributes attrs = Files.readAttributes(xml[i].toPath(), BasicFileAttributes.class); data[i][0] = xml[i].getName(); data[i][1] = String.format("%d B", attrs.size()); data[i][2] = String.format("%1$tY/%1$tm/%1$td", new Date(attrs.creationTime().toMillis())); data[i][3] = String.format("%1$tY/%1$tm/%1$td", new Date(attrs.lastModifiedTime().toMillis())); } } rows = xml.length; fireTableStructureChanged(); } catch (IOException ex) { System.err.println(ex.getMessage()); } } else JOptionPane.showMessageDialog(null, "No existen facturas de consumidor final"); }
public FileAttrs getAttrs() throws IOException { FileAttrs result; BasicFileAttributes attr; DosFileAttributes dosAttr; PosixFileAttributes posixAttr; result = new FileAttrs(); attr = Files.readAttributes(this.path.toPath(), BasicFileAttributes.class); result.setCtime(attr.creationTime().toMillis()); result.setMtime(attr.lastModifiedTime().toMillis()); // result.append("symlink", attr.isSymbolicLink()); //Redundant result.setSize(attr.size()); if (System.getProperty("os.name").startsWith("Windows")) { dosAttr = Files.readAttributes(this.path.toPath(), DosFileAttributes.class); result.setDosArchive(dosAttr.isArchive()); result.setDosHidden(dosAttr.isHidden()); result.setDosReadonly(dosAttr.isReadOnly()); result.setDosSystem(dosAttr.isSystem()); } else { posixAttr = Files.readAttributes(this.path.toPath(), PosixFileAttributes.class); result.setPosixSymlink(this.isSymlink()); if (result.getPosixSymlink()) { result.setLinkTo(Files.readSymbolicLink(this.path.toPath()).toString()); } result.setPosixOwner(posixAttr.owner().getName()); result.setPosixGroup(posixAttr.group().getName()); result.setPosixPermission(PosixFilePermissions.toString(posixAttr.permissions())); } return result; }
/** * Read the account requests from the .xml files that are stored in the * LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER) and stored those requests into * this.requests * * <p>1). read each .xml file 2). get the responsible staff for that request from Support Tracker * DB 3). create a HashMap object to store this request 4). add this request (HashMap object) into * the list that response by this staff 5). add responsileStaff as the key of the requests object * and the list of the requests that this staff responsible as the value of the requests object * * @return a map object, where: + its key is the name of the staff that responsible for the * requests + its value is the list of the request that this staff responsible for => each * request in this list is the Map object, where key is the attribute of the user, and value * is the value of that attribute @Note: if you want to see, how requests object look like, * please uncomment the print lines in this method. * @throws IOException if it failed to create DocumentBuilder object or failed to parse the * DocumentBuilder contents into a DOM object or failed to read the account requests from the * account requests storage folder */ private void extractRequests() throws IOException { logger.debug( "About to read the request *.xml file from the file system: " + LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER)); requests = new TreeMap<String, List<Map<String, String>>>(); try { // building DocumentBuilder DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); File outFolder = new File(LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER)); // outFolder doesn't exist because of the incorrect configured in ldap.properties // or it failed to read from that folder if (!outFolder.exists()) { String foldername = LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER); logger.error(ErrorConstants.FAIL_READING_ACCT_REQUEST + foldername); throw new IOException(ErrorConstants.FAIL_READING_ACCT_REQUEST + foldername); } // we need to order the request based on the date it created. // thats why, we convert the array of files to TreeSet object. TreeSet<File> xmlFiles = new TreeSet<File>(Arrays.asList(outFolder.listFiles())); // ADDITIONAL CODE - SPT-446 // Handle null case by creating empty array if (xmlFiles == null) { xmlFiles = new TreeSet<File>(); } for (File file : xmlFiles) { // read xml file, put the content into DocumentBuilder object // File file = xmlFiles[i]; if (file.getName().endsWith(".xml")) { // parse docBuilder contents into a DOM object (doc) Document doc = docBuilder.parse(file); NodeList fields = doc.getElementsByTagName("field"); logger.debug("Reading a file called: " + file.getName()); // get the data from DOM and store into HashMap String responsibleStaff = null; HashMap<String, String> maps = new HashMap<String, String>(); for (int j = 0; j < fields.getLength(); j++) { String key = fields.item(j).getAttributes().item(0).getTextContent(); maps.put(key, fields.item(j).getTextContent()); // looking for the company field // get the company name from the company field // find the staff who responsible for this request if (key.equalsIgnoreCase("company")) { try { responsibleStaff = SupportTrackerJDBC.getResponsibleStaff(fields.item(j).getTextContent()); } catch (SQLException e) { responsibleStaff = null; } } logger.debug( fields.item(j).getAttributes().item(0).getTextContent() + "|" + fields.item(j).getTextContent()); } String createdDate = null; try { createdDate = file.getName().replace(".xml", ""); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date date = sdf.parse(createdDate); sdf = new SimpleDateFormat("yyyy-MM-dd"); createdDate = sdf.format(date); } catch (Exception e) { BasicFileAttributes attrs = Files.readAttributes(Paths.get(file.getPath()), BasicFileAttributes.class); createdDate = attrs.creationTime().toString(); createdDate = createdDate.substring(0, createdDate.indexOf('T')); } maps.put("createdDate", createdDate); maps.put("filename", file.getName()); String countryCode = maps.get("c"); if (!countryCode.equals("") && countryCode != null) { maps.put("co", CountryCode.getCountryByCode(countryCode)); } // if there's no resposibleStaff stored in support tracker DB (when // responsibleStaff==null) // set responsibleStaff as "Others" if (responsibleStaff == null) responsibleStaff = "Others"; // add this request into its corresponding list ArrayList<Map<String, String>> requestResponsibleByThisStaff = null; if (requests.containsKey(responsibleStaff)) { requestResponsibleByThisStaff = (ArrayList<Map<String, String>>) requests.get(responsibleStaff); } else { requestResponsibleByThisStaff = new ArrayList<Map<String, String>>(); } requestResponsibleByThisStaff.add(maps); requests.put(responsibleStaff, requestResponsibleByThisStaff); } } // Note: if you want to see, how requests object look like, pls uncomment these lines // for(Map.Entry<String, List<Map<String, String>>> rqls : requests.entrySet()){ // String responsibleStaff = rqls.getKey(); // System.out.println(responsibleStaff); // List<Map<String, String>> requestList = rqls.getValue(); // int i = 1; // for(Map<String, String> request : requestList){ // System.out.println("\t" + i++ + ")."); // for(Map.Entry<String, String> attr_value : request.entrySet()){ // System.out.println("\t" + attr_value.getKey() + " : " + attr_value.getValue()); // } // } // } logger.debug("Finished reading the request *.xml."); } catch (ParserConfigurationException e) { String foldername = LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER); logger.error("Failed to create DocumentBuilder", e); new IOException(ErrorConstants.FAIL_READING_ACCT_REQUEST + foldername); } catch (SAXException e) { String foldername = LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER); logger.error("Failed to parse docBuilder contents into DOM object", e); new IOException(ErrorConstants.FAIL_READING_ACCT_REQUEST + foldername); } catch (IOException e) { String foldername = LdapProperty.getProperty(LdapConstants.OUTPUT_FOLDER); logger.error("Failed to parse docBuilder contents into DOM object", e); new IOException(ErrorConstants.FAIL_READING_ACCT_REQUEST + foldername); } }