public static void save(File file, byte[] content) throws IOException { File tmpFile = expandFilepath(file); mkdirsParent(tmpFile.toPath()); Files.copy(new ByteArrayInputStream(content), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); }
public static void save(File file, byte[] content) throws IOException { File tmpFile = expandFilepath(file); mkdirsParent(tmpFile.toPath()); Files.copy(new ByteArrayInputStream(content), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); }
protected FileOrValue buildFileOrValue(String content, String fileName) throws IOException { if (content == null) { return null; } Args.notNull(fileName, "fileName"); FileOrValue ret = new FileOrValue(); if (content.length() < 256) { ret.setValue(content); return ret; } File file = new File(baseDir, fileName); IoUtil.mkdirsParent(file.toPath()); IoUtil.save(file, content.getBytes("UTF-8")); ret.setFile(fileName); return ret; }
@Override protected Object execute0() throws Exception { source = expandFilepath(source); dest = expandFilepath(dest); File sourceFile = new File(source); if (!sourceFile.exists()) { throw new IllegalCmdParamException(source + " does not exist"); } if (!sourceFile.isFile()) { throw new IllegalCmdParamException(source + " is not a file"); } File destFile = new File(dest); if (destFile.exists()) { if (!destFile.isFile()) { throw new IllegalCmdParamException("cannot override an existing directory by a file"); } else { if (!force.booleanValue() && !confirm("Do you want to override the file " + dest, 3)) { return null; } } } else { IoUtil.mkdirsParent(destFile.toPath()); } FileUtils.copyFile(sourceFile, destFile, true); sourceFile.delete(); return null; }
@Override protected Object execute0() throws Exception { source = expandFilepath(source); dest = expandFilepath(dest); File sourceFile = new File(source); if (!sourceFile.exists()) { throw new IllegalCmdParamException(source + " does not exist"); } if (!sourceFile.isFile()) { throw new IllegalCmdParamException(source + " is not a file"); } File destFile = new File(dest); if (destFile.exists()) { if (!destFile.isFile()) { throw new IllegalCmdParamException("cannot override an existing directory by a file"); } else { if (!force.booleanValue() && !confirm("Do you want to override the file " + dest, 3)) { return null; } } } else { IoUtil.mkdirsParent(destFile.toPath()); } FileUtils.copyFile(sourceFile, destFile, true); return null; }
protected FileOrBinary buildFileOrBinary(byte[] content, String fileName) throws IOException { if (content == null) { return null; } Args.notNull(fileName, "fileName"); FileOrBinary ret = new FileOrBinary(); if (content.length < 256) { ret.setBinary(content); return ret; } File file = new File(baseDir, fileName); IoUtil.mkdirsParent(file.toPath()); IoUtil.save(file, content); ret.setFile(fileName); return ret; }