List of usage examples for java.io File getTotalSpace
public long getTotalSpace()
From source file:org.dcm4chee.dashboard.ui.filesystem.FileSystemPanel.java
@Override public void onBeforeRender() { super.onBeforeRender(); try {//from ww w . ja va 2 s. c o m DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new FileSystemModel()); for (String groupname : DashboardDelegator .getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listAllFileSystemGroups()) { FileSystemModel group = new FileSystemModel(); int index = groupname.indexOf("group="); if (index < 0) continue; group.setDirectoryPath(groupname.substring(index + 6)); group.setDescription(groupname + ",AET=" + DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .getDefaultRetrieveAETitle(groupname)); group.setGroup(true); DefaultMutableTreeNode groupNode; rootNode.add(groupNode = new DefaultMutableTreeNode(group)); File[] fileSystems = null; try { fileSystems = DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listFileSystemsOfGroup(groupname); } catch (MBeanException mbe) { } if (!((fileSystems == null) || (fileSystems.length == 0))) { long minBytesFree = DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .getMinimumFreeDiskSpaceOfGroup(groupname); for (File file : fileSystems) { FileSystemModel fsm = new FileSystemModel(); fsm.setDirectoryPath(file.getName()); fsm.setDescription( file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath()); fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA); fsm.setUsedDiskSpace( Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0)); fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setMinimumFreeDiskSpace( fsm.getOverallDiskSpaceLong() == 0 ? 0 : minBytesFree / FileSystemModel.MEGA); fsm.setUsableDiskSpace( Math.max((file.getUsableSpace() - minBytesFree) / FileSystemModel.MEGA, 0)); fsm.setRemainingTime(Math.max((file.getUsableSpace() - minBytesFree) / DashboardDelegator .getInstance((((BaseWicketApplication) getApplication()) .getInitParameter("DashboardServiceName"))) .getExpectedDataVolumePerDay(groupname), 0)); group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong()); group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong()); group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong()); group.setMinimumFreeDiskSpace( group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong()); group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong()); group.setRemainingTime(group.getRemainingTime() + fsm.getRemainingTime()); groupNode.add(new DefaultMutableTreeNode(fsm)); } } } String[] otherFileSystems = DashboardDelegator .getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listOtherFileSystems(); if (otherFileSystems != null && otherFileSystems.length > 0) { FileSystemModel group = new FileSystemModel(); group.setDirectoryPath( new ResourceModel("dashboard.filesystem.group.other").wrapOnAssignment(this).getObject()); group.setGroup(true); group.setRemainingTime(-1); DefaultMutableTreeNode groupNode; rootNode.add(groupNode = new DefaultMutableTreeNode(group)); for (String otherFileSystem : otherFileSystems) { File file = new File(otherFileSystem); FileSystemModel fsm = new FileSystemModel(); fsm.setDirectoryPath(file.getAbsolutePath()); fsm.setDescription(file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath()); fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA); fsm.setUsedDiskSpace( Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0)); fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setMinimumFreeDiskSpace(fsm.getOverallDiskSpaceLong() / FileSystemModel.MEGA); fsm.setUsableDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setRemainingTime(-1); group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong()); group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong()); group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong()); group.setMinimumFreeDiskSpace( group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong()); group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong()); group.setVisible(false); groupNode.add(new DefaultMutableTreeNode(fsm)); } } FileSystemTreeTable fileSystemTreeTable = new FileSystemTreeTable("filesystem-tree-table", new DefaultTreeModel(rootNode), new IColumn[] { new PropertyTreeColumn(new ColumnLocation(Alignment.LEFT, 25, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.name") .wrapOnAssignment(this).getObject(), "userObject.directoryPath"), new ImageRenderableColumn(new ColumnLocation(Alignment.MIDDLE, 30, Unit.PROPORTIONAL), new ResourceModel("dashboard.filesystem.table.column.image") .wrapOnAssignment(this).getObject(), "userObject.directoryPath"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.overall") .wrapOnAssignment(this).getObject(), "userObject.overallDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.used") .wrapOnAssignment(this).getObject(), "userObject.usedDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.free") .wrapOnAssignment(this).getObject(), "userObject.freeDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.minimumfree") .wrapOnAssignment(this).getObject(), "userObject.minimumFreeDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.usable") .wrapOnAssignment(this).getObject(), "userObject.usableDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 10, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.remainingtime") .wrapOnAssignment(this).getObject(), "userObject.remainingTimeString") }); fileSystemTreeTable.getTreeState().setAllowSelectMultiple(true); fileSystemTreeTable.getTreeState().collapseAll(); fileSystemTreeTable.setRootLess(true); addOrReplace(fileSystemTreeTable); } catch (Exception e) { log.error(this.getClass().toString() + ": " + "onBeforeRender: " + e.getMessage()); log.debug("Exception: ", e); throw new WicketRuntimeException(e.getLocalizedMessage(), e); } }
From source file:dev.dworks.apps.anexplorer.provider.ExternalStorageProvider.java
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection)); synchronized (mRootsLock) { for (String rootId : mIdToPath.keySet()) { final RootInfo root = mIdToRoot.get(rootId); final File path = mIdToPath.get(rootId); final RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, root.rootId); row.add(Root.COLUMN_FLAGS, root.flags); row.add(Root.COLUMN_TITLE, root.title); row.add(Root.COLUMN_DOCUMENT_ID, root.docId); row.add(Root.COLUMN_PATH, root.path); if (ROOT_ID_PRIMARY_EMULATED.equals(root.rootId) || root.rootId.startsWith(ROOT_ID_SECONDARY) || root.rootId.startsWith(ROOT_ID_PHONE)) { final File file = root.rootId.startsWith(ROOT_ID_PHONE) ? Environment.getRootDirectory() : path; row.add(Root.COLUMN_AVAILABLE_BYTES, file.getFreeSpace()); row.add(Root.COLUMN_TOTAL_BYTES, file.getTotalSpace()); }//from w w w. j av a2 s. c o m } } return result; }
From source file:org.dataconservancy.ui.it.FileHttpAPIIT.java
/** * Tests attempting getting a file that is no longer a part of a DataItem (DataItem). Expected return code 404 *//*w w w . jav a2 s . c o m*/ @Test public void testGetFile_DeprecatedFile() throws Exception { logStart("testGetFile_DeprecatedFile"); // Get all the original stuff back HttpAssert.assertStatus(httpClient, adminUserLogin, 300, 399, "Unable to login as admin user!"); final String fileId = dataSetToUpdate.getFiles().get(0).getId(); HttpGet request = new HttpGet(fileId); HttpResponse response = httpClient.execute(request); assertEquals("Expected a 200 response code!", 200, response.getStatusLine().getStatusCode()); assertNotNull("Expected an ETAG code!", response.getFirstHeader(ETAG)); assertNotNull("Expected a content disposition header!", response.getFirstHeader(CONTENT_DISPOSITION)); assertTrue("Expected content disposition to contain the file name!", response.getFirstHeader(CONTENT_DISPOSITION).getValue().contains(dataFileToUpdate.getName())); assertNotNull("Expected a content type header!", response.getFirstHeader(CONTENT_TYPE)); assertEquals("Expected a content type header of " + dataFileToUpdate.getFormat() + "!", dataFileToUpdate.getFormat(), response.getFirstHeader(CONTENT_TYPE).getValue()); assertNotNull("Expected a last modified header!", response.getFirstHeader(LAST_MODIFIED)); // I would like to test for the contents of the last modified header thusly // assertEquals("Expected a last modified header of " + dataSetToUpdate.getDepositDate() + "!", // dataSetToUpdate.getDepositDate().toString(), response.getFirstHeader(LAST_MODIFIED).getValue()); assertEquals(dataFileToUpdateContents, IOUtils.toString(response.getEntity().getContent())); // Set up a new file and update the dataset // A generic data file java.io.File newTempFile = java.io.File.createTempFile("FileHttpAPIITUpdated", ".txt"); newTempFile.deleteOnExit(); PrintWriter out = new PrintWriter(newTempFile); updatedDataFileContents = "Can haz MOAR data?"; out.print(updatedDataFileContents); out.close(); updatedDataFile = new DataFile(null, newTempFile.getName(), newTempFile.toURI().toURL().toExternalForm(), URLConnection.getFileNameMap().getContentTypeFor(newTempFile.getName()), newTempFile.getPath(), newTempFile.getTotalSpace(), new ArrayList<String>()); // A list of data files List<DataFile> newDataFileList = new ArrayList<DataFile>(); newDataFileList.add(updatedDataFile); // A dataset to contain the data file DateTime newDataSetDateTime = DateTime.now(); updatedDataSet = new DataItem("FileToUpdateHttpAPIIT Test DataItem", "Test DataItem to update for TestHttpAPIIT", dataSetToUpdate.getId(), approvedUser.getId(), newDataSetDateTime, newDataFileList, new ArrayList<String>(), collection.getId()); org.dataconservancy.ui.model.Package updatedPackage = new org.dataconservancy.ui.model.Package(); updatedPackage.setId(reqFactory.createIdApiRequest(PACKAGE).execute(httpClient)); DepositRequest updateRequest = reqFactory.createSingleFileDataItemDepositRequest(updatedPackage, dataSetToUpdate, collection.getId(), newTempFile); updateRequest.setIsUpdate(true); httpClient.execute(updateRequest.asHttpPost()).getEntity().getContent().close(); assertNotNull(archiveSupport.pollAndQueryArchiveForDataItem(updatedDataSet.getId())); String content; tryCount = 0; do { final String packageId = updatedPackage.getId(); final URI depositStatusUri = urlConfig.getDepositStatusUrl(packageId).toURI(); final HttpGet depositStatusRequest = new HttpGet(depositStatusUri); response = httpClient.execute(depositStatusRequest); assertFalse(404 == response.getStatusLine().getStatusCode()); assertTrue(response.getStatusLine().getStatusCode() < 500); content = IOUtils.toString(response.getEntity().getContent()); Thread.sleep(1000L); } while (!content.contains("DEPOSITED") && tryCount++ < maxTries); // Check for the old file request = buildGetRequest(getIDPart(dataSetToUpdate.getFiles().get(0).getId()), false); response = httpClient.execute(request); assertEquals("Expected a 404 response code!", 404, response.getStatusLine().getStatusCode()); response.getEntity().getContent().close(); httpClient.execute(logout).getEntity().getContent().close(); }
From source file:org.lockss.util.PlatformUtil.java
public DF getJavaDF(String path) { File f = null; try {/*from w ww .j a v a 2 s . c om*/ f = new File(path).getCanonicalFile(); } catch (IOException e) { f = new File(path).getAbsoluteFile(); } // mirror the df behaviour of returning null if path doesn't exist if (!f.exists()) { return null; } DF df = new DF(); df.path = path; df.size = f.getTotalSpace() / 1024; df.avail = f.getUsableSpace() / 1024; df.used = df.size - (f.getFreeSpace() / 1024); df.percent = Math.ceil((df.size - df.avail) * 100.00 / df.size); df.percentString = String.valueOf(Math.round(df.percent)) + "%"; df.percent /= 100.00; df.fs = null; df.mnt = longestRootFile(f); if (log.isDebug2()) log.debug2(df.toString()); return df; }
From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java
/** * ?//from www .j a v a 2 s . co m * * @return */ private List getLocalFileRoots() { List listroots = new ArrayList(); File[] roots = File.listRoots(); for (File file : roots) { if (file.getTotalSpace() <= 0) continue; TreeData treedata = new TreeData(file.getPath()); Map attr = new HashMap(); attr.put("path", file.getPath()); attr.put("totalSpace", CommonUtils.formatterDiskSize(file.getTotalSpace())); attr.put("freeSpace", CommonUtils.formatterDiskSize(file.getFreeSpace())); treedata.setId(file.getPath()); treedata.setAttributes(attr); listroots.add(treedata); } return listroots; }
From source file:com.amaze.filemanager.utils.Futils.java
public long[] getSpaces(HFile hFile) { if (!hFile.isSmb() && hFile.isDirectory()) { try {/*from w w w. j a va 2 s.co m*/ File file = new File(hFile.getPath()); long[] ints = new long[] { file.getTotalSpace(), file.getFreeSpace(), folderSize(new File(hFile.getPath())) }; return ints; } catch (Exception e) { return new long[] { -1, -1, -1 }; } } return new long[] { -1, -1, -1 }; }
From source file:org.dataconservancy.ui.it.FileHttpAPIIT.java
@Before public void setUp() throws Exception { adminUserLogin = reqFactory.createLoginRequest(adminUser).asHttpPost(); defaultUserLogin = reqFactory.createLoginRequest(defaultUser).asHttpPost(); approvedUserLogin = reqFactory.createLoginRequest(approvedUser).asHttpPost(); logout = reqFactory.createLogoutRequest().asHttpGet(); if (!areObjectsSeeded) { log.trace("Seeding objects ..."); HttpAssert.assertStatus(httpClient, adminUserLogin, 300, 399, "Unable to login as admin user!"); // A generic project with adminUser as a PI project = new Project(); project.setName("FileHttpAPIIT Test Project"); project.setDescription("Test Project For TestHttpAPIIT"); project.addNumber("123456"); project.setFundingEntity("Cash"); project.setStartDate(new DateTime(2012, 6, 13, 0, 0)); project.setEndDate(new DateTime(2013, 6, 13, 0, 0)); project.addPi(adminUser.getId()); project = reqFactory.createProjectApiAddRequest(project).execute(httpClient); log.trace("Seeded Project, id {}", project.getId()); log.trace(project.toString());//from w w w . j av a 2 s .c o m // A generic collection with approvedUser as a depositor collection = new Collection(); collection.setTitle("FileHttpAPIIT Test Collection"); collection.setSummary("Test Collection for TestHttpAPIIT"); collection.setId(reqFactory.createIdApiRequest(COLLECTION).execute(httpClient)); List<PersonName> creators = new ArrayList<PersonName>(); creators.add(new PersonName("Mr.", "John", "Jack", "Doe", "II")); collection.setCreators(creators); httpClient.execute(reqFactory.createCollectionRequest(collection, project).asHttpPost()).getEntity() .getContent().close(); HttpAssert.assertStatus(httpClient, new HttpGet(urlConfig.getViewCollectionUrl(collection.getId()).toURI()), 200, "Unable to create collection " + collection); log.trace("Seeded Collection, id {}", collection.getId()); log.trace(collection.toString()); httpClient.execute( reqFactory.createSetNewDepositorRequest(approvedUser.getId(), collection.getId()).asHttpPost()) .getEntity().getContent().close(); log.trace("Added depositor {} to Collection {}", approvedUser.getId(), collection.getId()); java.io.File tempFile = new java.io.File(FileHttpAPIIT.class.getResource(LINUX_FILE_ZIP_PATH).toURI()); dataFileContents = IOUtils.toByteArray(new FileInputStream(tempFile)); dataFileLengh = tempFile.length(); dataFile = new DataFile(null, tempFile.getName(), tempFile.toURI().toURL().toExternalForm(), URLConnection.getFileNameMap().getContentTypeFor(tempFile.getName()), tempFile.getPath(), tempFile.length(), new ArrayList<String>()); // A list of data files List<DataFile> dataFileList = new ArrayList<DataFile>(); dataFileList.add(dataFile); // A dataset to contain the data file dataSetDateTime = DateTime.now(); dataItem = new DataItem("FileHttpAPIIT Test DataItem", "Test DataItem for TestHttpAPIIT", reqFactory.createIdApiRequest(DATA_SET).execute(httpClient), approvedUser.getId(), dataSetDateTime, dataFileList, new ArrayList<String>(), collection.getId()); dataItem.setParentId(collection.getId()); dataFile.setParentId(dataItem.getId()); log.trace("Created DataItem with name {} and id {}", dataItem.getName(), dataItem.getId()); log.trace(dataItem.toString()); log.trace("DataItem ({}, {}) files:", dataItem.getName(), dataItem.getId()); for (DataFile f : dataItem.getFiles()) { log.trace("File id {}, name {}", f.getId(), f.getName()); } org.dataconservancy.ui.model.Package thePackage = new org.dataconservancy.ui.model.Package(); updatePackageId = reqFactory.createIdApiRequest(PACKAGE).execute(httpClient); thePackage.setId(updatePackageId); log.trace("Created Package, id {}", thePackage.getId()); log.trace(thePackage.toString()); httpClient.execute(reqFactory .createSingleFileDataItemDepositRequest(thePackage, dataItem, collection.getId(), tempFile) .asHttpPost()).getEntity().getContent().close(); // The Following construct seems suspicious. I am able to pull the // dataset from the archive via pollAndQueryArchiveForDataset, but // still end up making multiple calls to the getDepositStatusUrl // before I get back a deposited response. // I am, however, going to leave it be for now. dataItem = archiveSupport.pollAndQueryArchiveForDataItem(dataItem.getId()); String content; tryCount = 0; do { HttpResponse response = httpClient .execute(new HttpGet(urlConfig.getDepositStatusUrl(thePackage.getId()).toURI())); content = IOUtils.toString(response.getEntity().getContent()); Thread.sleep(1000L); } while (!content.contains("DEPOSITED") && tryCount++ < maxTries); log.trace("Seeded Package {} and DataItem {}, {}", new Object[] { thePackage.getId(), dataItem.getId(), dataItem.getName() }); log.trace(dataItem.toString()); for (DataFile f : dataItem.getFiles()) { log.trace(f.toString()); } // This is the datafile/dataset used in the deprecated file scenario java.io.File tempFileToUpdate = java.io.File.createTempFile("FileToUpdateHttpAPIIT", ".txt"); tempFileToUpdate.deleteOnExit(); PrintWriter updatedOut = new PrintWriter(tempFileToUpdate); dataFileToUpdateContents = "Can haz data? Again."; updatedOut.print(dataFileToUpdateContents); updatedOut.close(); dataFileToUpdate = new DataFile(null, tempFileToUpdate.getName(), tempFileToUpdate.toURI().toURL().toExternalForm(), URLConnection.getFileNameMap().getContentTypeFor(tempFileToUpdate.getName()), tempFileToUpdate.getPath(), tempFileToUpdate.getTotalSpace(), new ArrayList<String>()); // A list of data files List<DataFile> dataFileListToUpdate = new ArrayList<DataFile>(); dataFileListToUpdate.add(dataFileToUpdate); // A dataset to contain the data file dataSetDateTime = DateTime.now(); dataSetToUpdate = new DataItem("FileToUpdateHttpAPIIT Test DataItem", "Test DataItem to update for TestHttpAPIIT", reqFactory.createIdApiRequest(DATA_SET).execute(httpClient), approvedUser.getId(), dataSetDateTime, dataFileListToUpdate, new ArrayList<String>(), collection.getId()); dataSetToUpdate.setParentId(collection.getId()); dataFileToUpdate.setParentId(dataSetToUpdate.getId()); log.trace("Created DataItem with name {} and id {}", dataSetToUpdate.getName(), dataSetToUpdate.getId()); log.trace(dataSetToUpdate.toString()); log.trace("DataItem ({}, {}) files:", dataSetToUpdate.getName(), dataSetToUpdate.getId()); for (DataFile f : dataSetToUpdate.getFiles()) { log.trace("File id {}, name {}", f.getId(), f.getName()); } org.dataconservancy.ui.model.Package packageToUpdate = new org.dataconservancy.ui.model.Package(); packageToUpdate.setId(reqFactory.createIdApiRequest(PACKAGE).execute(httpClient)); httpClient.execute(reqFactory.createSingleFileDataItemDepositRequest(packageToUpdate, dataSetToUpdate, collection.getId(), tempFileToUpdate).asHttpPost()).getEntity().getContent().close(); dataSetToUpdate = archiveSupport.pollAndQueryArchiveForDataItem(dataSetToUpdate.getId()); tryCount = 0; do { HttpResponse response = httpClient .execute(new HttpGet(urlConfig.getDepositStatusUrl(packageToUpdate.getId()).toURI())); content = IOUtils.toString(response.getEntity().getContent()); Thread.sleep(1000L); } while (!content.contains("DEPOSITED") && tryCount++ < maxTries); log.trace("Seeded Package {} and DataItem {}, {}", new Object[] { thePackage.getId(), dataSetToUpdate.getId(), dataSetToUpdate.getName() }); log.trace(dataSetToUpdate.toString()); for (DataFile f : dataSetToUpdate.getFiles()) { log.trace(f.toString()); } httpClient.execute(logout).getEntity().getContent().close(); areObjectsSeeded = true; } }
From source file:eu.optimis.vc.api.IsoCreator.IsoImageCreation.java
private void storeAgents(File scriptsDirectory) { if (virtualMachine.isHasIPS() || virtualMachine.isHasBTKey() || virtualMachine.isHasVPNKey()) { LOGGER.debug("Adding agents to ISO"); // Add the agent tar ball String agentsTarBallName = "vpn.tar.gz"; // Agents tar ball source File agentsTarBallFileSource = new File( configuration.getAgentsDirectory() + File.separator + agentsTarBallName); LOGGER.debug("agentsTarBallFileSource is: " + agentsTarBallFileSource.getPath()); // Destination folder File agentsIsoDirectory = new File(isoDataDirectory + File.separator + "agents"); agentsIsoDirectory.mkdirs();//from w ww . j ava 2s. c o m LOGGER.debug("agentsIsoDirectory is: " + agentsIsoDirectory.getPath()); // Agents tar ball destination File agentsTarBallFileDestination = new File(agentsIsoDirectory + File.separator + agentsTarBallName); LOGGER.debug("agentsTarBallFileDestination is: " + agentsTarBallFileDestination.getPath()); // Copy the file to the iso directory LOGGER.debug("Copying agent file to ISO directory..."); FileChannel source = null; FileChannel destination = null; try { if (!agentsTarBallFileDestination.exists()) { agentsTarBallFileDestination.createNewFile(); } source = new FileInputStream(agentsTarBallFileSource).getChannel(); destination = new FileOutputStream(agentsTarBallFileDestination).getChannel(); destination.transferFrom(source, 0, source.size()); LOGGER.debug( "Copied agent file to ISO directory, size is : " + agentsTarBallFileDestination.length()); agentsTarBallFileDestination.getTotalSpace(); } catch (IOException e) { LOGGER.error( "Failed to create agents tar ball with path: " + agentsTarBallFileDestination.getPath(), e); } finally { if (source != null) { try { source.close(); } catch (IOException e) { LOGGER.error("Failed to close source agents tar ball file with path: " + agentsTarBallFileSource.getPath(), e); } } if (destination != null) { try { destination.close(); } catch (IOException e) { LOGGER.error("Failed to close destination agents tar ball file with path: " + agentsTarBallFileDestination.getPath(), e); } } } // Add the agent script File agentsFile = new File(scriptsDirectory + File.separator + "agents.sh"); try { LOGGER.debug(ATTEMPTING_TO_CREATE_FILE + agentsFile.getPath()); agentsFile.createNewFile(); LOGGER.debug(CREATED_FILE + agentsFile.getPath()); // TODO: This should be stored somewhere else and not hardcoded // Mount location is currently hard coded in the init.d scripts // of the base VM /mnt/context/ String agentsScript = "#!/bin/bash\n" + "#Setup environment\n" + "touch /var/lock/subsys/local\n" + "source /etc/profile\n" + "\n" + "#Extract the agent from the ISO agent directory to /opt/optimis/vpn/\n" + "mkdir -p /opt/optimis\n" + "tar zxvf /mnt/context/agents/" + agentsTarBallName + " -C /opt/optimis/\n" + "chmod -R 777 /opt/optimis/vpn\n" + "\n" + "#Install and start the agents\n" + "\n"; // Add VPN install and init script to // /mnt/context/scripts/agents.sh if (virtualMachine.isHasIPS()) { agentsScript += "#IPS\n" + "/opt/optimis/vpn/IPS_Meta.sh\n" + "/bin/date > /opt/optimis/vpn/dsa.log\n" + "\n"; } // Add VPN install and init script to // /mnt/context/scripts/agents.sh ? // KMS if (virtualMachine.isHasBTKey()) { agentsScript += "#KMS\n" + "/opt/optimis/vpn/KMS_Meta.sh\n" + "/bin/date >> /opt/optimis/vpn/scagent.log\n" + "\n"; } // Add VPN install and init script to // /mnt/context/scripts/agents.sh if (virtualMachine.isHasVPNKey()) { agentsScript += "#VPN\n" + "/opt/optimis/vpn/VPN_Meta.sh\n"; } // Write out the agents file FileOutputStream fos = new FileOutputStream(agentsFile.getPath()); fos.write(agentsScript.getBytes()); fos.close(); LOGGER.debug("Writing agents script complete!"); } catch (IOException e) { LOGGER.error("Failed to create agents script file with path: " + agentsFile.getPath(), e); } } else { LOGGER.debug("Agents not not needed by service!"); } }
From source file:org.openspaces.pu.container.servicegrid.PUServiceBeanImpl.java
private long copyPu(String puPath, File puWorkFolder) throws IOException { String puDeployPath = context.getServiceBeanManager().getOperationalStringManager().getDeployPath() + "/" + puPath;/* ww w.ja v a 2 s . co m*/ File src = new File(puDeployPath); logger.info("Copying from GSM [" + puDeployPath + "] to " + "[" + deployPath + "] ..."); FileSystemUtils.copyRecursively(src, puWorkFolder); return src.getTotalSpace(); }
From source file:net.sf.jvifm.ui.FileLister.java
private void generateOneItemForWinRoot(TableItem item, File file, int index) { item.setText(0, file.getPath().substring(0, 2)); item.setText(1, StringUtil.formatSize(file.getTotalSpace())); item.setText(2, StringUtil.formatSize(file.getFreeSpace())); item.setImage(0, driveImage);/* w w w . j a v a 2s . com*/ String selection = (String) historyManager.getSelectedItem(""); //$NON-NLS-1$ if (file.getPath().equalsIgnoreCase(selection + File.separator)) { currentRow = index; } }