.split(","); try { String cookiesFileContent = IoUtils.streamToString(IoUtils.readFile(PhantomJsDriver.cookiesFile)); for (String cookieName : cookieNames) { int cookieIndex = cookiesFileContent.indexOf(cookieName + "=");
/** * Utility to silently close a {@link Closeable} item (in/out stream, writer, etc.) if not null. * Does not throw IO exception that might arise. It is just logged. * @param closeable stream to close * @return <code>false</code> if close operation had been issued but not completed successfully */ public static boolean closeStream( Closeable closeable ) { return closeStream(closeable, null); }
/** * * @param downloadDir The download directory where the files will be downloaded to. */ public void setDownloadDir( String downloadDir ) { this.downloadDir = IoUtils.normalizeDirPath(downloadDir); }
/** * Constructor used for unit testing and mocking * * @param atsAgent the address of the remote ATS agent where the entity is located on * @param absolutePath the absolute path and name of the entity, e.g. /root/file.ext * @param osType the operating system of the machine */ FilePackage( String atsAgent, String absolutePath, OperatingSystemType osType, FileSystemOperations fileSystemOperations, SystemOperations systemOperations ) { this.atsAgent = atsAgent; this.path = IoUtils.getFilePath(absolutePath); this.name = IoUtils.getFileName(absolutePath); this.osType = osType; this.fileSystemOperations = fileSystemOperations; this.systemOperations = systemOperations; }
/** * Convert the {@link InputStream} to {@link String} and close the passed stream * * @param inputStream the input stream * @return a string representation of the input data * @throws IOException */ public static String streamToString( InputStream inputStream ) throws IOException { try { return new String(loadInputStreamToMemory(inputStream)); } finally { IoUtils.closeStream(inputStream); } }
private String normalizePath( boolean isFile, String path ) { if (path == null) { return null; } if (isFile) { path = IoUtils.normalizeFilePath(path); } else { path = IoUtils.normalizeDirPath(path); } return path.replace("//", "/").replace("\\\\", "\\"); }
private void backupAllFilesInDirectory( File origDir ) throws EnvironmentCleanupException { File[] files = origDir.listFiles(); if (files == null) { throw new EnvironmentCleanupException("No such directory '" + origDir + "'."); } for (File file : files) { if (file.isDirectory()) { backupAllFilesInDirectory(file); } else { String backupFileName = IoUtils.normalizeFilePath(getFileCanonicalPath(file)); // important that case matches incl. drive letter so origDirName and backupDir // should also come after getCanonicalPath() invocation backupFileName = backupFileName.replace(origDirName, getBackupDir()); new FileEnvironmentUnit(getFileCanonicalPath(file), IoUtils.getFilePath(backupFileName), file.getName()).backup(); } } // if the directory is empty - create the new empty directory in the backup folder if (files.length == 0) { String backupDir = IoUtils.normalizeDirPath(getFileCanonicalPath(origDir)) .replace(origDirName, getBackupDir()); new File(backupDir).mkdirs(); } }
try { is = resultSet.getAsciiStream(index); value = IoUtils.streamToString(is); } finally { IoUtils.closeStream(is);
String agentFolder = IoUtils.normalizeDirPath(extractAgentZip(agentZip)); String fileName = IoUtils.getFileName(pathInfo.getSftpPath()); String filePath = sourceProjectInfo.findFile(fileName); if (filePath == null) {
stdOut = IoUtils.streamToString(process.getInputStream()).trim(); stdErr = IoUtils.streamToString(process.getErrorStream()).trim();
File dirPath = new File(IoUtils.getFilePath(backupFile)); if (!dirPath.exists()) { dirPath.mkdirs(); throw new FileSystemSnapshotException("Error saving " + backupFile, e); } finally { IoUtils.closeStream(fos, "Error closing IO stream to file used for file system snapshot backup " + backupFile);
boolean hidden ) { sourceFile = IoUtils.normalizeFilePath(sourceFile, osType); checkFileExistence(new File(sourceFile)); String filePath = IoUtils.getFilePath(sourceFile); String fileName = IoUtils.getFileName(sourceFile); if (hidden) { if (fileName.startsWith(".")) {
out = new FileOutputStream(entryDestination); copyStream(in, out); } finally { closeStream(out); closeStream(in);
final String tempPath = IoUtils.normalizeDirPath(AtsSystemProperties.SYSTEM_USER_TEMP_DIR + "/ats_tmp/"); String agentFolderName = tempPath + "agent_" + String.valueOf(agentZip.lastModified()); IoUtils.unzip(agentZipPath, agentFolderName, true); } catch (IOException ioe) {
checkParamLengthForSocketTransfer(fileNameLength, "file name length"); String fileName = readString(dis, fileNameLength); fileName = IoUtils.normalizeFilePath(fileName, osType); // switch file separators according to the current OS File file = new File(fileName); if (fdType.equals(FILE_COPY_SOCKET_COMMAND)) { fileSize -= readBytes; IoUtils.closeStream(fos); } else if (fdType.equals(DIR_CREATE_SOCKET_COMMAND)) { } finally { IoUtils.closeStream(fos); IoUtils.closeStream(dis); if (socket != null) { try {
String line = IoUtils.readLineWithEOL(reader); if (line != null) { sb.append(line); line = IoUtils.readLineWithEOL(reader); + "' from byte position " + fromBytePosition, e); } finally { IoUtils.closeStream(reader);
DirectorySnapshot( String path, FileSystemEqualityState equality ) { this.path = IoUtils.normalizeUnixDir(path.trim()); this.equality = equality; }
private void checkIfArchiveFormatIsSupported( String archiveFilePath ) { if (archiveFilePath.endsWith(".zip")) { return; } else if (archiveFilePath.endsWith(".gz") && !archiveFilePath.endsWith(".tar.gz")) { return; } else if (archiveFilePath.endsWith("tar.gz")) { return; } else if (archiveFilePath.endsWith(".tar")) { return; } else { String[] filenameTokens = IoUtils.getFileName(archiveFilePath).split("\\."); if (filenameTokens.length <= 1) { throw new FileSystemOperationException("Archive format was not provided."); } else { throw new FileSystemOperationException("Archive with format '" + filenameTokens[filenameTokens.length - 1] + "' is not supported. Available once are 'zip', 'gz', 'tar' and 'tar.gz' ."); } } }
protected void createDirIfNotExist( String fileName ) throws EnvironmentCleanupException { String filePath = IoUtils.getFilePath(fileName); File directory = new File(filePath); if (directory != null && !directory.exists()) { if (directory.mkdirs()) { log.info("Directory was created: \"" + filePath + "\"."); } else { throw new EnvironmentCleanupException("Could not create directory: " + getFileCanonicalPath(directory)); } } }
mapFileDocument = mapFile; } else { mapFileDocument = IoUtils.normalizeUnixDir(UiEngineConfigurator.getInstance() .getMapFilesBaseDir()) + mapFile; mapFileDocument = IoUtils.normalizeUnixFile(mapFileDocument);