List of usage examples for org.apache.commons.io FileUtils ONE_KB
long ONE_KB
To view the source code for org.apache.commons.io FileUtils ONE_KB.
Click Source Link
From source file:org.apache.geode.management.internal.cli.functions.SizeExportLogsFunctionFileTest.java
@Test public void bothFiles_returnsCombinedSize() throws Exception { List<File> logFiles = createLogFiles(new File(dir.getName(), testName.getMethodName()), 1, 1, FileUtils.ONE_KB); File logFile = logFiles.get(0); long logFileSize = FileUtils.sizeOf(logFiles.get(0)); List<File> statFiles = createStatFiles(new File(dir.getName(), testName.getMethodName()), 1, 1, FileUtils.ONE_KB);/*from ww w .j a va 2 s . co m*/ File statArchive = statFiles.get(0); long statFileSize = FileUtils.sizeOf(statArchive); SizeExportLogsFunction function = new SizeExportLogsFunction(); assertThat(function.estimateLogFileSize(this.member, logFile, statArchive, nonFilteringArgs)) .isEqualTo(logFileSize + statFileSize); }
From source file:org.apache.geode.management.internal.cli.functions.SizeExportLogsFunctionFileTest.java
@Test public void manyFiles_returnsCombinedSize() throws Exception { expectedSize = 0;/* w ww. j a v a2s.c o m*/ List<File> logFiles = createLogFiles(new File(dir.getName(), testName.getMethodName()), 1, 3, FileUtils.ONE_KB); logFiles.forEach((file) -> { expectedSize += FileUtils.sizeOf(file); }); List<File> statFiles = createStatFiles(new File(dir.getName(), testName.getMethodName()), 1, 2, FileUtils.ONE_KB * 2); statFiles.forEach((file) -> { expectedSize += FileUtils.sizeOf(file); }); SizeExportLogsFunction function = new SizeExportLogsFunction(); assertThat(function.estimateLogFileSize(this.member, logFiles.get(0), statFiles.get(0), nonFilteringArgs)) .isEqualTo(expectedSize); }
From source file:org.apache.sling.commons.log.logback.internal.TestLogWriter.java
@Test public void testSizeBasedLegacyPattern() { LogWriter lw = new LogWriter("foo", "target/foo", 5, "4k"); Appender<ILoggingEvent> a = createappender(lw); assertInstanceOf(a, SlingRollingFileAppender.class); SlingRollingFileAppender sr = (SlingRollingFileAppender) a; assertInstanceOf(sr.getTriggeringPolicy(), SizeBasedTriggeringPolicy.class); assertInstanceOf(sr.getRollingPolicy(), FixedWindowRollingPolicy.class); SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) sr.getTriggeringPolicy(); FixedWindowRollingPolicy fwRp = (FixedWindowRollingPolicy) sr.getRollingPolicy(); assertEquals(5, fwRp.getMaxIndex()); assertEquals(String.valueOf(4 * FileUtils.ONE_KB), sbtp.getMaxFileSize()); }
From source file:org.apache.sling.extensions.logback.internal.TestLogWriter.java
@Test public void testSizeBasedLegacyPattern() { LogWriter lw = new LogWriter("target/foo", 5, "4k"); Appender<ILoggingEvent> a = createappender(lw); assertInstanceOf(a, SlingRollingFileAppender.class); SlingRollingFileAppender sr = (SlingRollingFileAppender) a; assertInstanceOf(sr.getTriggeringPolicy(), SizeBasedTriggeringPolicy.class); assertInstanceOf(sr.getRollingPolicy(), FixedWindowRollingPolicy.class); SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) sr.getTriggeringPolicy(); FixedWindowRollingPolicy fwRp = (FixedWindowRollingPolicy) sr.getRollingPolicy(); assertEquals(5, fwRp.getMaxIndex()); assertEquals(String.valueOf(4 * FileUtils.ONE_KB), sbtp.getMaxFileSize()); }
From source file:org.archive.crawler.framework.CrawlJob.java
/** * Refresh knowledge of total launched and last launch by scanning * the job.log. //www . ja v a2 s . c om */ protected void scanJobLog() { File jobLog = getJobLog(); launchCount = 0; if (!jobLog.exists()) return; try { Pattern launchLine = Pattern.compile("(\\S+) (\\S+) Job launched"); long startPosition = 0; if (jobLog.length() > FileUtils.ONE_KB * 100) { isLaunchInfoPartial = true; startPosition = jobLog.length() - (FileUtils.ONE_KB * 100); } FileInputStream jobLogIn = new FileInputStream(jobLog); jobLogIn.getChannel().position(startPosition); BufferedReader jobLogReader = new BufferedReader(new InputStreamReader(jobLogIn)); String line; while ((line = jobLogReader.readLine()) != null) { Matcher m = launchLine.matcher(line); if (m.matches()) { launchCount++; lastLaunch = new DateTime(m.group(1)); } } jobLogReader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.duracloud.syncoptimize.data.TestDataHandler.java
public void createTestData(File dataDir, int numFiles, int xMB) throws IOException { File file = new File(dataDir, "test-file.txt"); FileWriter writer = new FileWriter(file); StringBuilder textBuilder = new StringBuilder(); for (int x = 0; x < FileUtils.ONE_KB; ++x) { textBuilder.append("x"); }// w w w . j a va 2s . c o m String text = textBuilder.toString(); for (int y = 0; y < FileUtils.ONE_KB * xMB; ++y) { writer.write(text); } IOUtils.closeQuietly(writer); for (int z = 1; z < numFiles; ++z) { String filename = "test-file-" + z + ".txt"; FileUtils.copyFile(file, new File(dataDir, filename)); } }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Converts the passed value into a string in Mb and returns a string * version of it./*from w w w. j a v a2 s . c o m*/ * * @param v The value to convert. * @return See above. */ public static String formatFileSize(long v) { if (v <= 0) return ""; String s = ""; if (v < FileUtils.ONE_KB) s = String.format("%.1f", (double) v) + " bytes"; else if (v >= FileUtils.ONE_KB && v < FileUtils.ONE_MB) s = String.format("%.1f", ((double) v / FileUtils.ONE_KB)) + " Kb"; else if (v >= FileUtils.ONE_MB && v < FileUtils.ONE_GB) s = String.format("%.1f", ((double) v / FileUtils.ONE_MB)) + " Mb"; else if (v >= FileUtils.ONE_GB) s = String.format("%.1f", ((double) v / FileUtils.ONE_GB)) + " Gb"; return s; }
From source file:org.openvpms.web.component.mail.MailEditor.java
/** * Helper to format a size.//ww w . java 2 s .c o m * * @param size the size, in bytes * @return the formatted size */ private String getSize(long size) { String result; if (size / FileUtils.ONE_GB > 0) { result = getSize(size, FileUtils.ONE_GB, "mail.size.GB"); } else if (size / FileUtils.ONE_MB > 0) { result = getSize(size, FileUtils.ONE_MB, "mail.size.MB"); } else if (size / FileUtils.ONE_KB > 0) { result = getSize(size, FileUtils.ONE_KB, "mail.size.KB"); } else { result = Messages.format("mail.size.bytes", size); } return result; }
From source file:sharedcode.turboeditor.texteditor.PageSystem.java
public PageSystem(Context context, PageSystemInterface pageSystemInterface, String text, @Nullable File file) { final int charForPage = 15000; final int MAX_KBs_WITHOUT_PAGE_SYSTEM = 50; this.pageSystemInterface = pageSystemInterface; pages = new LinkedList<>(); final boolean dimensionOverLimit; if (file != null && file.exists() && file.isFile()) dimensionOverLimit = FileUtils.sizeOf(file) >= MAX_KBs_WITHOUT_PAGE_SYSTEM * FileUtils.ONE_KB; else//from w w w. ja v a2 s . com dimensionOverLimit = false; int i = 0; int to; int nextIndexOfReturn; final int textLength = text.length(); boolean pageSystemEnabled = PreferenceHelper.getSplitText(context); if (pageSystemEnabled && dimensionOverLimit) { while (i < textLength) { to = i + charForPage; nextIndexOfReturn = text.indexOf("\n", to); if (nextIndexOfReturn > to) to = nextIndexOfReturn; if (to > text.length()) to = text.length(); pages.add(text.substring(i, to)); i = to + 1; } if (i == 0) pages.add(""); } else { pages.add(text); } startingLines = new int[pages.size()]; setStartingLines(); }