public ByteBuffer getByteBufferFromDisk(User user, int dashId, int deviceId, PinType pinType, short pin, int count, GraphGranularityType type, int skipCount) { Path userDataFile = Paths.get( dataFolder, FileUtils.getUserStorageDir(user.email, user.appName), generateFilename(dashId, deviceId, pinType, pin, type) ); if (Files.exists(userDataFile)) { try { return FileUtils.read(userDataFile, count, skipCount); } catch (Exception ioe) { log.error(ioe); } } return null; }
@SuppressWarnings("unchecked") public TokensPool(String dataFolder) { this.dataFolder = dataFolder; Path path = Paths.get(dataFolder, TOKENS_TEMP_FILENAME); this.tokens = (ConcurrentHashMap<String, BaseToken>) deserialize(path); FileUtils.deleteQuietly(path); }
private boolean isOutdated(Path filePath, long now) throws IOException { long lastModified = FileUtils.getLastModified(filePath); return lastModified + exportExpirePeriod < now; }
long fileSize = Files.size(userReportingFile); if (fileSize > maxRecordsCount * REPORTING_RECORD_SIZE) { ByteBuffer userReportingData = FileUtils.read(userReportingFile, maxRecordsCount); try (OutputStream os = Files.newOutputStream(userReportingFile, TRUNCATE_EXISTING)) {
FileUtils.getUserStorageDir(keyToRemove.getEmail(), keyToRemove.getAppName())); if (Files.notExists(userReportFolder)) { Files.createDirectories(userReportFolder); Path filePath = Paths.get(userReportFolder.toString(), fileName); FileUtils.write(filePath, value.calcAverage(), keyToRemove.getTs(type));
private Path getUserReportingFolderPath(User user) { return Paths.get(dataFolder, FileUtils.getUserStorageDir(user.email, user.appName)); }
this.textHolder = new TextHolder(gcmProperties); this.downloadUrl = FileUtils.downloadUrl(serverProperties.host, props.getProperty("http.port"), props.getBoolProperty("force.port.80.for.csv")
public static String getBuildPatternFromString(Path path) { try { return getPatternFromString(path, "\0" + "build" + "\0"); } catch (IOException ioe) { log.error("Error getting pattern from file. Reason : {}", ioe.getMessage()); throw new RuntimeException(ioe); } }
private Stream<User> restoreFromBackup(Path restoreFileNamePath) { log.info("Trying to recover from backup..."); String filename = restoreFileNamePath.toString(); try { File[] files = backupDataDir.toFile().listFiles( (dir, name) -> name.startsWith(filename) ); File backupFile = FileUtils.getLatestFile(files); if (backupFile == null) { log.info("Didn't find any files for recovery :(."); return Stream.empty(); } log.info("Found {}. You are lucky today :).", backupFile.getAbsoluteFile()); User user = JsonParser.parseUserFromFile(backupFile); makeProfileChanges(user); //profile saver thread is launched after file manager is initialized. //so making sure user profile will be saved //this is not very important as profile will be updated by user anyway. user.lastModifiedTs = System.currentTimeMillis() + 10 * 1000; log.info("Restored.", backupFile.getAbsoluteFile()); return Stream.of(user); } catch (Exception e) { //ignore log.error("Restoring from backup failed. {}", e.getMessage()); } return Stream.empty(); }
protected long generateReport() { long now = System.currentTimeMillis(); String date = LocalDate.now(report.tzName).toString(); Path userCsvFolder = FileUtils.getUserReportDir( key.user.email, key.user.appName, key.reportId, date); try { Profile profile = key.user.profile; DashBoard dash = profile.getDashByIdOrThrow(key.dashId); report.lastRunResult = generateReport(userCsvFolder, profile, dash, now); } catch (IllegalCommandException illegalState) { report.lastRunResult = ReportResult.ERROR; log.debug("Dashboard is not exists anymore for the report {} for user {}. ", report.id, key.user.email); } catch (Exception e) { report.lastRunResult = ReportResult.ERROR; log.error("Error generating report {} for user {}. ", report.id, key.user.email); log.error("Error: ", e); } long newNow = System.currentTimeMillis(); log.info("Processed report for {}, time {} ms.", key.user.email, newNow - now); return newNow; }
path = FileUtils.getPathForLocalRun(uri);
try { Path path = file.toPath(); ByteBuffer userReportingData = FileUtils.read(path, count); write(file, userReportingData); System.out.println("Successfully copied. Truncated : "
this.textHolder = new TextHolder(new GCMProperties(Collections.emptyMap())); this.downloadUrl = FileUtils.downloadUrl(serverProperties.host, props.getProperty("http.port"), props.getBoolProperty("force.port.80.for.csv")
private static void delete(String userReportingDir, int dashId, int deviceId, PinType pinType, short pin, GraphGranularityType reportGranularity) { Path userDataFile = Paths.get(userReportingDir, generateFilename(dashId, deviceId, pinType, pin, reportGranularity)); FileUtils.deleteQuietly(userDataFile); }
@SuppressWarnings("unchecked") public AverageAggregatorProcessor(String dataFolder) { this.dataFolder = dataFolder; Path path; path = Paths.get(dataFolder, MINUTE_TEMP_FILENAME); this.minute = (ConcurrentHashMap<AggregationKey, AggregationValue>) deserialize(path); FileUtils.deleteQuietly(path); path = Paths.get(dataFolder, HOURLY_TEMP_FILENAME); this.hourly = (ConcurrentHashMap<AggregationKey, AggregationValue>) deserialize(path); FileUtils.deleteQuietly(path); path = Paths.get(dataFolder, DAILY_TEMP_FILENAME); this.daily = (ConcurrentHashMap<AggregationKey, AggregationValue>) deserialize(path); FileUtils.deleteQuietly(path); }
public int delete(User user, Function<Path, Boolean> filter) { log.debug("Removing all reporting data for {}", user.email); Path reportingFolderPath = getUserReportingFolderPath(user); int removedFilesCounter = 0; try { if (Files.exists(reportingFolderPath)) { try (DirectoryStream<Path> reportingFolder = Files.newDirectoryStream(reportingFolderPath, "*")) { for (Path reportingFile : reportingFolder) { if (filter.apply(reportingFile)) { log.trace("Removing {}", reportingFile); FileUtils.deleteQuietly(reportingFile); removedFilesCounter++; } } } } } catch (Exception e) { log.error("Error removing file : {}.", reportingFolderPath); } return removedFilesCounter; }
public int delete(User user, int dashId, int deviceId) throws IOException { log.debug("Removing all pin data for dashId {}, deviceId {}.", dashId, deviceId); Path userReportingPath = getUserReportingFolderPath(user); int count = 0; if (Files.exists(userReportingPath)) { String fileNamePrefix = generateFilenamePrefix(dashId, deviceId); try (DirectoryStream<Path> userReportingFolder = Files.newDirectoryStream(userReportingPath, "*")) { for (Path reportingFile : userReportingFolder) { if (reportingFile.getFileName().toString().startsWith(fileNamePrefix)) { FileUtils.deleteQuietly(reportingFile); count++; } } } } return count; }
public int delete(User user, int dashId, int deviceId, String[] pins) throws IOException { log.debug("Removing selected pin data for dashId {}, deviceId {}.", dashId, deviceId); Path userReportingPath = getUserReportingFolderPath(user); int count = 0; List<String> prefixes = new ArrayList<>(); for (String pin : pins) { prefixes.add(generateFilenamePrefix(dashId, deviceId, pin)); } try (DirectoryStream<Path> userReportingFolder = Files.newDirectoryStream(userReportingPath, "*")) { for (Path reportingFile : userReportingFolder) { String userFileName = reportingFile.getFileName().toString(); if (containsPrefix(prefixes, userFileName)) { FileUtils.deleteQuietly(reportingFile); count++; } } } return count; }