List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:Main.java
public static void main(String[] args) { File file = new File("c:\\java.exe"); long size = file.length(); String display = FileUtils.byteCountToDisplaySize(size); System.out.println("Name = " + file.getName()); System.out.println("size = " + size); System.out.println("Display = " + display); }
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); client.connect("ftp.domain.com"); client.login("admin", "secret"); String[] names = client.listNames(); for (String name : names) { System.out.println("Name = " + name); }/* ww w .j a va 2s. co m*/ FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { // Check if FTPFile is a regular file if (ftpFile.getType() == FTPFile.FILE_TYPE) { System.out.println("FTPFile: " + ftpFile.getName() + "; " + FileUtils.byteCountToDisplaySize(ftpFile.getSize())); } } client.logout(); client.disconnect(); }
From source file:com.puffywhiteshare.PWSApp.java
/** * @param args//from w ww . j a va 2 s .c om * @throws IOException */ public static void main(String[] args) throws IOException { CloudBucket cloud = new CloudBucket(); logger.info("Test my output bitches"); Yaml y = new Yaml(); File f = new File("Playing.yml"); FileInputStream fis = new FileInputStream(f); Map m = (Map) y.load(fis); Long startFiles = System.currentTimeMillis(); Iterator<File> fileIterator = FileUtils.iterateFiles(new File("/Users/chad/Pictures/."), null, true); do { File file = fileIterator.next(); cloud.add(file); } while (fileIterator.hasNext()); Long endFiles = System.currentTimeMillis(); System.out.println("Files processing took " + ((endFiles - startFiles))); Long startSer = System.currentTimeMillis(); String filename = "cloud.ser"; FileOutputStream fos = null; ObjectOutputStream out = null; try { fos = new FileOutputStream(filename); out = new ObjectOutputStream(fos); out.writeObject(cloud); out.close(); } catch (IOException ex) { ex.printStackTrace(); } Long endSer = System.currentTimeMillis(); System.out.println("Files processing took " + ((endSer - startSer))); logger.info(" Size = " + FileUtils.byteCountToDisplaySize(cloud.getSize())); logger.info("Count = " + cloud.getCount()); /* Set<String> buckets = m.keySet(); System.out.println(m.toString()); for(String bucket : buckets) { logger.info("Bucket = " + bucket); logger.info("Folders = " + m.get(bucket)); List<Object> folders = (List<Object>) m.get(bucket); for(Object folder : folders) { if(folder instanceof String) { logger.info("Folder Root = " + folder); } else if(folder instanceof Map) { logger.info("Folder Map = " + folder); } } BlockingQueue<File> fileFeed = new ArrayBlockingQueue<File>(10); Map folderMap = (Map) m.get(bucket); Set<String> folders = folderMap.entrySet(); for(String folder : folders) { logger.info("Folder = " + folder); } } */ }
From source file:com.l2jserver.model.template.SkillTemplateConverter.java
public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException, JAXBException { Class.forName("com.mysql.jdbc.Driver"); final File target = new File("data/templates"); final JAXBContext c = JAXBContext.newInstance(SkillTemplate.class, LegacySkillList.class); final Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD); System.out.println("Generating template XML files..."); c.generateSchema(new SchemaOutputResolver() { @Override/*from w ww . j a v a 2s . c om*/ public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { return new StreamResult(new File(target, suggestedFileName)); } }); try { final Unmarshaller u = c.createUnmarshaller(); final Marshaller m = c.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "skill"); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "skill ../skill.xsd"); Collection<File> files = FileUtils.listFiles(new File(LEGACY_SKILL_FOLDER), new String[] { "xml" }, true); for (final File legacyFile : files) { LegacySkillList list = (LegacySkillList) u.unmarshal(legacyFile); for (final LegacySkill legacySkill : list.skills) { SkillTemplate t = fillSkill(legacySkill); final File file = new File(target, "skill/" + t.id.getID() + (t.getName() != null ? "-" + camelCase(t.getName()) : "") + ".xml"); templates.add(t); try { m.marshal(t, getXMLSerializer(new FileOutputStream(file))); } catch (MarshalException e) { System.err.println( "Could not generate XML template file for " + t.getName() + " - " + t.getID()); file.delete(); } } } System.out.println("Generated " + templates.size() + " templates"); System.gc(); System.out.println("Free: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory())); System.out.println("Total: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory())); System.out.println("Used: " + FileUtils.byteCountToDisplaySize( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); System.out.println("Max: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())); } finally { conn.close(); } }
From source file:com.l2jserver.model.template.NPCTemplateConverter.java
public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException, JAXBException { controllers.put("L2Teleporter", TeleporterController.class); controllers.put("L2CastleTeleporter", TeleporterController.class); controllers.put("L2Npc", BaseNPCController.class); controllers.put("L2Monster", MonsterController.class); controllers.put("L2FlyMonster", MonsterController.class); Class.forName("com.mysql.jdbc.Driver"); final File target = new File("generated/template/npc"); System.out.println("Scaning legacy HTML files..."); htmlScannedFiles = FileUtils.listFiles(L2J_HTML_FOLDER, new String[] { "html", "htm" }, true); final JAXBContext c = JAXBContext.newInstance(NPCTemplate.class, Teleports.class); final Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD); {/*w ww.j av a 2 s . c o m*/ System.out.println("Converting teleport templates..."); teleportation.teleport = CollectionFactory.newList(); final Marshaller m = c.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); final PreparedStatement st = conn.prepareStatement("SELECT * FROM teleport"); st.execute(); final ResultSet rs = st.getResultSet(); while (rs.next()) { final TeleportationTemplate template = new TeleportationTemplate(); template.id = new TeleportationTemplateID(rs.getInt("id"), null); template.name = rs.getString("Description"); TemplateCoordinate coord = new TemplateCoordinate(); coord.x = rs.getInt("loc_x"); coord.y = rs.getInt("loc_y"); coord.z = rs.getInt("loc_z"); template.point = coord; template.price = rs.getInt("price"); template.item = rs.getInt("itemId"); if (rs.getBoolean("fornoble")) { template.restrictions = new Restrictions(); template.restrictions.restriction = Arrays.asList("NOBLE"); } teleportation.teleport.add(template); } m.marshal(teleportation, getXMLSerializer(new FileOutputStream(new File(target, "../teleports.xml")))); // System.exit(0); } System.out.println("Generating template XML files..."); // c.generateSchema(new SchemaOutputResolver() { // @Override // public Result createOutput(String namespaceUri, // String suggestedFileName) throws IOException { // // System.out.println(new File(target, suggestedFileName)); // // return null; // return new StreamResult(new File(target, suggestedFileName)); // } // }); try { final Marshaller m = c.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); final PreparedStatement st = conn.prepareStatement( "SELECT npc.*, npcskills.level AS race " + "FROM npc " + "LEFT JOIN npcskills " + "ON(npc.idTemplate = npcskills.npcid AND npcskills.skillid = ?)"); st.setInt(1, 4416); st.execute(); final ResultSet rs = st.getResultSet(); while (rs.next()) { Object[] result = fillNPC(rs); NPCTemplate t = (NPCTemplate) result[0]; String type = (String) result[1]; String folder = createFolder(type); if (folder.isEmpty()) { m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "npc ../npc.xsd"); } else { m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "npc ../../npc.xsd"); } final File file = new File(target, "npc/" + folder + "/" + t.getID().getID() + (t.getInfo().getName() != null ? "-" + camelCase(t.getInfo().getName().getValue()) : "") + ".xml"); file.getParentFile().mkdirs(); templates.add(t); try { m.marshal(t, getXMLSerializer(new FileOutputStream(file))); } catch (MarshalException e) { System.err.println("Could not generate XML template file for " + t.getInfo().getName().getValue() + " - " + t.getID()); file.delete(); } } System.out.println("Generated " + templates.size() + " templates"); System.gc(); System.out.println("Free: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory())); System.out.println("Total: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory())); System.out.println("Used: " + FileUtils.byteCountToDisplaySize( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); System.out.println("Max: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())); } finally { conn.close(); } }
From source file:de.burlov.amazon.s3.dirsync.CLI.java
/** * @param args//from ww w. j a va 2 s.c o m */ @SuppressWarnings("static-access") public static void main(String[] args) { Logger.getLogger("").setLevel(Level.OFF); Logger deLogger = Logger.getLogger("de"); deLogger.setLevel(Level.INFO); Handler handler = new ConsoleHandler(); handler.setFormatter(new VerySimpleFormatter()); deLogger.addHandler(handler); deLogger.setUseParentHandlers(false); // if (true) // { // LogFactory.getLog(CLI.class).error("test msg", new Exception("test extception")); // return; // } Options opts = new Options(); OptionGroup gr = new OptionGroup(); /* * Befehlsgruppe initialisieren */ gr = new OptionGroup(); gr.setRequired(true); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download changed or new files").create(CMD_UPDATE)); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download directory snapshot").create(CMD_SNAPSHOT)); gr.addOption(OptionBuilder.withDescription("Delete remote folder").create(CMD_DELETE_DIR)); gr.addOption(OptionBuilder.withDescription("Delete a bucket").create(CMD_DELETE_BUCKET)); gr.addOption(OptionBuilder.create(CMD_HELP)); gr.addOption(OptionBuilder.create(CMD_VERSION)); gr.addOption(OptionBuilder.withDescription("Prints summary for stored data").create(CMD_SUMMARY)); gr.addOption(OptionBuilder.withDescription("Clean up orphaned objekts").create(CMD_CLEANUP)); gr.addOption(OptionBuilder.withDescription("Changes encryption password").withArgName("new password") .hasArg().create(CMD_CHANGE_PASSWORD)); gr.addOption(OptionBuilder.withDescription("Lists all buckets").create(CMD_LIST_BUCKETS)); gr.addOption(OptionBuilder.withDescription("Lists raw objects in a bucket").create(CMD_LIST_BUCKET)); gr.addOption(OptionBuilder.withDescription("Lists files in remote folder").create(CMD_LIST_DIR)); opts.addOptionGroup(gr); /* * Parametergruppe initialisieren */ opts.addOption(OptionBuilder.withArgName("key").isRequired(false).hasArg().withDescription("S3 access key") .create(OPT_S3S_KEY)); opts.addOption(OptionBuilder.withArgName("secret").isRequired(false).hasArg() .withDescription("Secret key for S3 account").create(OPT_S3S_SECRET)); opts.addOption(OptionBuilder.withArgName("bucket").isRequired(false).hasArg().withDescription( "Optional bucket name for storage. If not specified then an unique bucket name will be generated") .create(OPT_BUCKET)); // opts.addOption(OptionBuilder.withArgName("US|EU").hasArg(). // withDescription( // "Where the new bucket should be created. Default US").create( // OPT_LOCATION)); opts.addOption(OptionBuilder.withArgName("path").isRequired(false).hasArg() .withDescription("Local directory path").create(OPT_LOCAL_DIR)); opts.addOption(OptionBuilder.withArgName("name").isRequired(false).hasArg() .withDescription("Remote directory name").create(OPT_REMOTE_DIR)); opts.addOption(OptionBuilder.withArgName("password").isRequired(false).hasArg() .withDescription("Encryption password").create(OPT_ENC_PASSWORD)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs() .withDescription("Comma separated exclude file patterns like '*.tmp,*/dir/*.tmp'") .create(OPT_EXCLUDE_PATTERNS)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs().withDescription( "Comma separated include patterns like '*.java'. If not specified, then all files in specified local directory will be included") .create(OPT_INCLUDE_PATTERNS)); if (args.length == 0) { printUsage(opts); return; } CommandLine cmd = null; try { cmd = new GnuParser().parse(opts, args); if (cmd.hasOption(CMD_HELP)) { printUsage(opts); return; } if (cmd.hasOption(CMD_VERSION)) { System.out.println("s3dirsync version " + Version.CURRENT_VERSION); return; } String awsKey = cmd.getOptionValue(OPT_S3S_KEY); String awsSecret = cmd.getOptionValue(OPT_S3S_SECRET); String bucket = cmd.getOptionValue(OPT_BUCKET); String bucketLocation = cmd.getOptionValue(OPT_LOCATION); String localDir = cmd.getOptionValue(OPT_LOCAL_DIR); String remoteDir = cmd.getOptionValue(OPT_REMOTE_DIR); String password = cmd.getOptionValue(OPT_ENC_PASSWORD); String exclude = cmd.getOptionValue(OPT_EXCLUDE_PATTERNS); String include = cmd.getOptionValue(OPT_INCLUDE_PATTERNS); if (StringUtils.isBlank(awsKey) || StringUtils.isBlank(awsSecret)) { System.out.println("S3 account data required"); return; } if (StringUtils.isBlank(bucket)) { bucket = awsKey + ".dirsync"; } if (cmd.hasOption(CMD_DELETE_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } int deleted = S3Utils.deleteBucket(awsKey, awsSecret, bucket); System.out.println("Deleted objects: " + deleted); return; } if (cmd.hasOption(CMD_LIST_BUCKETS)) { for (String str : S3Utils.listBuckets(awsKey, awsSecret)) { System.out.println(str); } return; } if (cmd.hasOption(CMD_LIST_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } for (String str : S3Utils.listObjects(awsKey, awsSecret, bucket)) { System.out.println(str); } return; } if (StringUtils.isBlank(password)) { System.out.println("Encryption password required"); return; } char[] psw = password.toCharArray(); DirSync ds = new DirSync(awsKey, awsSecret, bucket, bucketLocation, psw); ds.setExcludePatterns(parseSubargumenths(exclude)); ds.setIncludePatterns(parseSubargumenths(include)); if (cmd.hasOption(CMD_SUMMARY)) { ds.printStorageSummary(); return; } if (StringUtils.isBlank(remoteDir)) { System.out.println("Remote directory name required"); return; } if (cmd.hasOption(CMD_DELETE_DIR)) { ds.deleteFolder(remoteDir); return; } if (cmd.hasOption(CMD_LIST_DIR)) { Folder folder = ds.getFolder(remoteDir); if (folder == null) { System.out.println("No such folder found: " + remoteDir); return; } for (Map.Entry<String, FileInfo> entry : folder.getIndexData().entrySet()) { System.out.println(entry.getKey() + " (" + FileUtils.byteCountToDisplaySize(entry.getValue().getLength()) + ")"); } return; } if (cmd.hasOption(CMD_CLEANUP)) { ds.cleanUp(); return; } if (cmd.hasOption(CMD_CHANGE_PASSWORD)) { String newPassword = cmd.getOptionValue(CMD_CHANGE_PASSWORD); if (StringUtils.isBlank(newPassword)) { System.out.println("new password required"); return; } char[] chars = newPassword.toCharArray(); ds.changePassword(chars); newPassword = null; Arrays.fill(chars, ' '); return; } if (StringUtils.isBlank(localDir)) { System.out.println(OPT_LOCAL_DIR + " argument required"); return; } String direction = ""; boolean up = false; boolean snapshot = false; if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_UPDATE))) { direction = cmd.getOptionValue(CMD_UPDATE); } else if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_SNAPSHOT))) { direction = cmd.getOptionValue(CMD_SNAPSHOT); snapshot = true; } if (StringUtils.isBlank(direction)) { System.out.println("Operation direction required"); return; } up = StringUtils.equalsIgnoreCase(OPT_UP, direction); File baseDir = new File(localDir); if (!baseDir.exists() && !baseDir.mkdirs()) { System.out.println("Invalid local directory: " + baseDir.getAbsolutePath()); return; } ds.syncFolder(baseDir, remoteDir, up, snapshot); } catch (DirSyncException e) { System.out.println(e.getMessage()); e.printStackTrace(); } catch (ParseException e) { System.out.println(e.getMessage()); printUsage(opts); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:com.nuvolect.deepdive.show.Do_info.java
/** * * Display file information//from w w w. j a v a 2 s . c o m */ public static void cmd_info(Activity act) { m_act = act; String NL = "\n"; OmniFile file = Data.m_files.get(Data.m_selectedPosition); String title = Data.m_selectedName; String message = "" + "Size: " + FileUtils.byteCountToDisplaySize(file.length()); if (OmniImage.isImage(file)) message += NL + "Dimensions: " + OmniImage.getDim(file); message += NL + "MimeType: " + MimeUtil.getMime(file); LogUtil.log(LogUtil.LogType.DO_INFO, "info: " + message); DialogUtil.dismissDialog(m_act, title, message); }
From source file:com.qwazr.utils.RuntimeUtils.java
public static String getMemoryUsagePretty() { return FileUtils.byteCountToDisplaySize(getMemoryUsage()); }
From source file:jease.cms.service.Informatons.java
public static String getDatabaseSize() { return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(new File(getDatabaseDirectory()))); }
From source file:com.dycody.android.idealnote.helpers.AttachmentsHelper.java
/** * Retrieves attachment file size//from w w w. j a v a 2 s . c o m * * @param attachment Attachment to evaluate * @return Human readable file size string */ public static String getSize(Attachment attachment) { long sizeInKb = attachment.getSize(); if (attachment.getSize() == 0) { sizeInKb = new File(attachment.getUri().getPath()).length(); } return FileUtils.byteCountToDisplaySize(sizeInKb); }