本文整理汇总了Java中org.parboiled.common.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于org.parboiled.common包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSuiteFileName
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public static String getSuiteFileName() throws IOException {
File temp = File.createTempFile("parboiled_testng_suite", ".xml");
temp.deleteOnExit();
String xml = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n" +
"<suite name=\"parboiled-core\">\n" +
" <test verbose=\"1\" name=\"parboiled-core\" annotations=\"JDK\">\n" +
" <packages>\n" +
" <package name=\"org.parboiled.*\" />\n" +
" </packages>\n" +
" </test>\n" +
"</suite>";
FileUtils.writeAllText(xml, temp);
return temp.getCanonicalPath();
}
示例2: getSuiteFileName
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public static String getSuiteFileName() throws IOException {
File temp = File.createTempFile("parboiled_testng_suite", ".xml");
temp.deleteOnExit();
String xml = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n" +
"<suite name=\"examples-java\">\n" +
" <test verbose=\"1\" name=\"examples-java\" annotations=\"JDK\">\n" +
" <packages>\n" +
" <package name=\"org.parboiled.*\" />\n" +
" </packages>\n" +
" </test>\n" +
"</suite>";
FileUtils.writeAllText(xml, temp);
return temp.getCanonicalPath();
}
示例3: getSuiteFileName
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public static String getSuiteFileName() throws IOException {
File temp = File.createTempFile("parboiled_testng_suite", ".xml");
temp.deleteOnExit();
String xml = "" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n" +
"<suite name=\"parboiled-java\">\n" +
" <test verbose=\"1\" name=\"parboiled-java\" annotations=\"JDK\">\n" +
" <packages>\n" +
" <package name=\"org.parboiled.*\" />\n" +
" </packages>\n" +
" </test>\n" +
" <test verbose=\"1\" name=\"NoPackageParser\" annotations=\"JDK\">\n" +
" <classes>\n" +
" <class name=\"NoPackageParser\"/>\n" +
" </classes>" +
" </test>\n" +
"</suite>";
FileUtils.writeAllText(xml, temp);
return temp.getCanonicalPath();
}
示例4: loadBinaryResource
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public static byte[] loadBinaryResource(URL resourceUrl, String pluginName) {
try {
File file = urlToFileMaybe(resourceUrl, pluginName);
if (file == null) {
return IOUtils.toByteArray(resourceUrl.openStream());
} else {
return FileUtils.readAllBytes(file);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: loadResourceFromUrl
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public static String loadResourceFromUrl(URL resourceUrl, String pluginName) throws IOException {
File file = urlToFileMaybe(resourceUrl, pluginName) ;
if (file != null) {
return FileUtils.readAllText(file, Charset.forName("UTF-8"));
} else {
return IOUtils.toString(resourceUrl, Charset.forName("UTF-8"));
}
}
示例6: writeMigrationToFile
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public void writeMigrationToFile(Integer migrationNumber, GenerateResult result) {
String prefix = StringUtils.leftPad(migrationNumber.toString(), 5, '0');
File dir = new File(System.getProperty("user.dir") + "/src/main/resources/sql");
File migrationsFile = new File(System.getProperty("user.dir") + "/src/main/resources/sql/migrations.txt");;
if (dir.exists() && migrationsFile.exists()) {
String name = prefix + "-" + result.getChangePrefix()
+ ".mysql.js";
File newMigrationFile = new File(dir.getAbsolutePath() + "/" + name);
FileUtils.writeAllText(result.getSqlJs(), newMigrationFile, Charset.forName("UTF-8"));
// Append the new migration to the text file with a list of migrations
String s = FileUtils.readAllText(migrationsFile);
if (!s.endsWith("\n")) {
s += "\n";
}
s += prefix + "-" + result.getChangePrefix();
FileUtils.writeAllText(s, migrationsFile, Charset.forName("UTF-8"));
} else {
String file = Settings.instance().getTargetFolder() + "/sql/" + prefix + "-" + result.getChangePrefix()
+ ".mysql.js";
FileUtils.writeAllText(result.getSqlJs(), new File(file), Charset.forName("UTF-8"));
}
}
示例7: getLastMigrationNumber
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public int getLastMigrationNumber() {
Integer max = 0;
File migrationsFile = new File(System.getProperty("user.dir") + "/src/main/resources/sql/migrations.txt");
if (migrationsFile.exists()) {
for(String line: FileUtils.readAllText(migrationsFile, UTF8).split("\\n")) {
line = StringUtils.strip(line);
if (empty(line)) {
continue;
}
if (line.startsWith("//") || line.startsWith("#")) {
continue;
}
int dash = line.indexOf("-");
if (dash == -1) {
continue;
}
Integer version = Integer.valueOf(StringUtils.stripStart(line.substring(0, dash), "0"));
if (version >= max) {
max = version;
}
}
} else {
for (SqlMigration migration : new SqlMigrationAction().getUserMigrations()) {
if (migration.getVersionNumber() > max) {
max = migration.getVersionNumber();
}
}
}
return max;
}
示例8: testIndentDedentInputBuffer2
import org.parboiled.common.FileUtils; //导入依赖的package包/类
@Test
public void testIndentDedentInputBuffer2() {
String input = FileUtils.readAllTextFromResource("IndentDedentBuffer2.test");
InputBuffer buf = new IndentDedentInputBuffer(input.toCharArray(), 4, "#", false);
String bufContent = collectContent(buf);
assertEquals(bufContent, FileUtils.readAllTextFromResource("IndentDedentBuffer2.converted.test"));
String text = "go deep";
int start = bufContent.indexOf(text);
assertEquals(buf.extract(start, start + text.length()), text);
}
示例9: testIndentDedentInputBuffer3
import org.parboiled.common.FileUtils; //导入依赖的package包/类
@Test
public void testIndentDedentInputBuffer3() {
String input = FileUtils.readAllTextFromResource("IndentDedentBuffer3.test");
InputBuffer buf = new IndentDedentInputBuffer(input.toCharArray(), 4, "//", false);
String bufContent = collectContent(buf);
assertEquals(bufContent, FileUtils.readAllTextFromResource("IndentDedentBuffer3.converted.test"));
assertEquals(buf.extract(0, bufContent.length()), input);
}
示例10: testJavaErrorRecovery
import org.parboiled.common.FileUtils; //导入依赖的package包/类
@Test
public void testJavaErrorRecovery() {
JavaParser parser = Parboiled.createParser(JavaParser.class);
String[] tests = FileUtils.readAllTextFromResource("JavaErrorRecoveryTest.test")
.split("###\r?\n");
if (!runSingleTest(parser, tests)) {
// no single, important test found, so run all tests
for (String test : tests) {
runTest(parser, test);
}
}
}
示例11: testCalculatorErrorRecovery
import org.parboiled.common.FileUtils; //导入依赖的package包/类
@Test
public void testCalculatorErrorRecovery() {
CalculatorParser parser = Parboiled.createParser(CalculatorParser1.class);
String[] tests = FileUtils.readAllTextFromResource("CalculatorErrorRecoveryTest.test").split("###\r?\n");
if (!runSingleTest(parser, tests)) {
// no single, important test found, so run all tests
for (String test : tests) {
runTest(parser, test);
}
}
}
示例12: renderToGraphViz
import org.parboiled.common.FileUtils; //导入依赖的package包/类
@SuppressWarnings({"UnusedDeclaration"})
private static void renderToGraphViz(String dotSource) throws Exception {
String command = "/usr/local/bin/dot -Tpng";
String output = "/Users/mathias/Downloads/graph.png";
final Process process = Runtime.getRuntime().exec(command);
FileUtils.copyAll(new ByteArrayInputStream(dotSource.getBytes("UTF-8")), process.getOutputStream());
new Thread(new Runnable() {
public void run() {
FileUtils.copyAll(process.getErrorStream(), System.err);
}
}).start();
FileUtils.copyAll(process.getInputStream(), new FileOutputStream(output));
process.waitFor();
}
示例13: getUserMigrations
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public List<SqlMigration> getUserMigrations() {
List<SqlMigration> migrations = list();
File sqlDirectory = new File(settings().getTargetFolder() + "/sql");
if (!sqlDirectory.isDirectory()) {
Log.finer("Sql directory does not exist {0}", sqlDirectory.getAbsoluteFile());
return migrations;
}
Log.finer("Find sql files in {0}", sqlDirectory.getAbsolutePath());
for (File file: sqlDirectory.listFiles()) {
Log.finer("Scan file" + file.getAbsolutePath());
if (!set("js", "sql").contains(FilenameUtils.getExtension(file.getAbsolutePath()))) {
Log.finer("Extension is not .js or .sql {0}", file.getAbsolutePath());
continue;
}
if (file.getName().startsWith(".") || file.getName().startsWith("#")) {
Log.finer("File name starts with invalid character {0}", file.getName());
continue;
}
if (!file.getName().contains("." + DB.instance().getDbImplementation().getName().toLowerCase() + ".")) {
Log.finer("File name does not contain the name of the current database engine: \".{0}.\"", DB.instance().getDbImplementation().getName().toLowerCase());
continue;
}
if (!file.getName().contains("-")) {
Log.finer("File name does not have version part {0}", file.getName());
continue;
}
String versionString = StringUtils.stripStart(StringUtils.split(file.getName(), "-")[0], "0");
if (!StringUtils.isNumeric(versionString)) {
Log.finer("File name does not have numeric version part {0}", file.getName());
continue;
}
Log.info("Load SQL file for migration: {0}", file.getName());
migrations.add(
new SqlMigration()
.setVersionNumber(Integer.parseInt(StringUtils.stripStart(versionString, "0")))
.setAppName("")
.setFilename(file.getName())
.setSource(FileUtils.readAllText(file))
);
}
migrations.sort(new PropertyComparator<>("versionNumber"));
return migrations;
}
示例14: writeMultiPartToLocalFile
import org.parboiled.common.FileUtils; //导入依赖的package包/类
protected File writeMultiPartToLocalFile(U uploaded) throws IOException {
stRequest.setAsMultiPartRequest();
final String path = stRequest.getParameter("destination");
final Part filePart = stRequest.getPart("file");
String fullFileName = getFileNameFromPart(filePart);
String extension = FilenameUtils.getExtension(fullFileName);
String fileName = truncate(fullFileName, 85);
String relativePath = GeneralUtils.slugify(truncate(FilenameUtils.getBaseName(fullFileName), 75)) + "-" + DateUtils.mils() + "." + extension;
relativePath = "stallion-file-" + uploaded.getId() + "/" + GeneralUtils.secureRandomToken(8) + "/" + relativePath;
String destPath = uploadsFolder + relativePath;
FileUtils.forceMkdir(new File(destPath).getParentFile());
uploaded
.setCloudKey(relativePath)
.setExtension(extension)
.setName(fileName)
.setOwnerId(Context.getUser().getId())
.setUploadedAt(DateUtils.utcNow())
.setType(fileController.getTypeForExtension(extension))
;
// Make raw URL
String url = makeRawUrlForFile(uploaded, "org");
uploaded.setRawUrl(url);
fileController.save(uploaded);
OutputStream out = null;
InputStream filecontent = null;
boolean failed = true;
File outFile = new File(destPath);
Long amountRead = 0L;
Long maxSize = Settings.instance().getUserUploads().getMaxFileSizeBytes();
try {
out = new FileOutputStream(destPath);
filecontent = filePart.getInputStream();
int read = 0;
final byte[] bytes = new byte[1024];
while ((read = filecontent.read(bytes)) != -1) {
amountRead += read;
if (amountRead > maxSize) {
throw new ClientException("Uploaded file exceeded max size of " + maxSize + " bytes.");
}
out.write(bytes, 0, read);
}
failed = false;
Log.info("File{0}being uploaded to {1}",
new Object[]{fileName, path});
uploaded.setSizeBytes(amountRead);
} finally {
if (out != null) {
out.close();
}
if (filecontent != null) {
filecontent.close();
}
if (failed) {
if (outFile.exists()) {
outFile.delete();
}
}
}
return new File(destPath);
}
示例15: createResized
import org.parboiled.common.FileUtils; //导入依赖的package包/类
public void createResized(U uploaded, BufferedImage image, String orgPath, int targetHeight, int targetWidth, String postfix, Scalr.Mode scalrMode) throws IOException {
String imageFormat = uploaded.getExtension();
BufferedImage scaledImg = Scalr.resize(image, Scalr.Method.QUALITY, scalrMode,
targetWidth, targetHeight, Scalr.OP_ANTIALIAS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int height = scaledImg.getHeight();
int width = scaledImg.getWidth();
ImageIO.write(scaledImg, imageFormat, baos);
baos.flush();
byte[] scaledImageInByte = baos.toByteArray();
baos.close();
String relativePath = FilenameUtils.removeExtension(uploaded.getCloudKey());
if (!"org".equals(postfix)) {
relativePath = relativePath + "." + postfix;
}
relativePath = relativePath + "." + uploaded.getExtension();
String thumbnailPath = this.uploadsFolder + relativePath;
Log.info("Write all byptes to {0}", thumbnailPath);
FileUtils.writeAllBytes(scaledImageInByte, new File(thumbnailPath));
Long sizeBytes = new File(thumbnailPath).length();
//String url = "{cdnUrl}/st-publisher/files/view/" + uploaded.getSecret() + "/" + uploaded.getId() + "/" + postfix + "?ts=" + DateUtils.mils();
String url = makeRawUrlForFile(uploaded, postfix);
if (postfix.equals("thumb")) {
uploaded.setThumbCloudKey(relativePath);
uploaded.setThumbRawUrl(url);
uploaded.setThumbHeight(height);
uploaded.setThumbWidth(width);
} else if (postfix.equals("small")) {
uploaded.setSmallCloudKey(relativePath);
uploaded.setSmallRawUrl(url);
uploaded.setSmallHeight(height);
uploaded.setSmallWidth(width);
} else if (postfix.equals("medium")) {
uploaded.setMediumCloudKey(relativePath);
uploaded.setMediumRawUrl(url);
uploaded.setMediumHeight(height);
uploaded.setMediumWidth(width);
} else if (postfix.equals("org")) {
uploaded.setCloudKey(relativePath);
uploaded.setRawUrl(url);
uploaded.setSizeBytes(sizeBytes);
uploaded.setHeight(height);
uploaded.setWidth(width);
}
//return scaledImageInByte;
}