当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil.copy方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileUtil.copy方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.copy方法的具体用法?Java FileUtil.copy怎么用?Java FileUtil.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileUtil的用法示例。


在下文中一共展示了FileUtil.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveResourceAsFile

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public static FileObject saveResourceAsFile(FileObject destDir, String resourcePath) throws IOException {
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
    String filename = filenameFromPath(resourcePath);
    FileObject outFile = destDir.getFileObject(filename);
    if (outFile == null) {
        outFile = destDir.createData(filename);
    }
    OutputStream out = outFile.getOutputStream();
    if (in != null && out != null) {
        try {
            FileUtil.copy(in, out);
            return outFile;
        } finally {
            in.close();
            out.close();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SaasUtil.java

示例2: unzip

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void unzip(File what, File where) throws IOException {
    JarFile jf = new JarFile(what);
    Enumeration<JarEntry> en = jf.entries();

    while (en.hasMoreElements()) {
        JarEntry current = en.nextElement();
        if (current.isDirectory()) continue;
        File target = new File(where, current.getName());
        target.getParentFile().mkdirs();
        assertTrue(target.getParentFile().isDirectory());
        InputStream in = jf.getInputStream(current);
        OutputStream out = new BufferedOutputStream(new FileOutputStream(target));

        FileUtil.copy(in, out);

        in.close();
        out.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:BinaryAnalyserTest.java

示例3: copy

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void copy(File fromFile, File toFile) throws IOException {
    if(fromFile.isFile()) {
        InputStream is = new FileInputStream (fromFile);
        OutputStream os = new FileOutputStream(toFile);
        FileUtil.copy(is, os);
        is.close();
        os.close();
    } else {
        toFile.mkdirs();
        File[] files = fromFile.listFiles();
        if( files == null || files.length == 0) {
            return;
        }
        for(File f : files) {
            copy(f, new File(toFile, f.getName()));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:TestVCSInterceptor.java

示例4: copyStringToFileObject

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
protected FileObject copyStringToFileObject(FileObject fo, String content) throws Exception {
    OutputStream os = fo.getOutputStream();
    try {
        InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
        FileUtil.copy(is, os);
        return fo;
    } finally {
        os.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:SourceTestSupport.java

示例5: setupLocalWadl

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private FileObject setupLocalWadl() throws Exception {
    FileObject workDir = FileUtil.toFileObject(getWorkDir());
    FileObject wadl = workDir.getFileObject("application.wadl.xml");
    if (wadl == null) {
        wadl = workDir.createData("application.wadl.xml");
    }
    OutputStream out = wadl.getOutputStream();
    try {
        FileUtil.copy(getClass().getResourceAsStream("application.wadl"), out);
    } finally {
        out.close();
    }
    return wadl;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:SaasServicesModelTest.java

示例6: copyBuildNativeTemplate

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
static FileObject copyBuildNativeTemplate(@NonNull final Project project) throws IOException {
    Parameters.notNull("project", project); //NOI18N
    final FileObject buildExFoBack = project.getProjectDirectory().getFileObject(String.format(
        "%s~",  //NOI18N
        EXTENSION_BUILD_SCRIPT_PATH));
    if (buildExFoBack != null) {
        closeInEditor(buildExFoBack);
        buildExFoBack.delete();
    }
    FileObject buildExFo = project.getProjectDirectory().getFileObject(EXTENSION_BUILD_SCRIPT_PATH);
    FileLock lock;
    if (buildExFo != null) {
        closeInEditor(buildExFo);
        lock = buildExFo.lock();
        try {
            buildExFo.rename(
                lock,
                buildExFo.getName(),
                String.format(
                    "%s~",  //NOI18N
                    buildExFo.getExt()));
        } finally {
            lock.releaseLock();
        }
    }
    buildExFo = FileUtil.createData(project.getProjectDirectory(), EXTENSION_BUILD_SCRIPT_PATH);
    lock = buildExFo.lock();
    try (final InputStream in = J2SEDeployProperties.class.getClassLoader().getResourceAsStream(BUILD_SCRIPT_PROTOTYPE);
         final OutputStream out = buildExFo.getOutputStream(lock)) {
        FileUtil.copy(in, out);
    } finally {
        lock.releaseLock();
    }
    return buildExFo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:J2SEDeployProperties.java

示例7: testPartialRead

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
public void testPartialRead () throws IOException {
    final String testString = "test-1test-2test-3test-4";
    final File test = new File(getWorkDir(), "testPartialRead.orig");
    PrintWriter _out = new PrintWriter (new FileWriter (test));
    _out.print (testString);
    _out.close();        
    FileObject fo = FileUtil.toFileObject(test);        
    assertNotNull(fo);
    
    
    Charset encoding = FileEncodingQuery.getEncoding(fo);
    InputStream ins = fo.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FileUtil.copy(ins, baos);
    ins.close();
    byte[] arr = baos.toByteArray();
    baos.close();
    baos = null;
    
    final Reader in = new InputStreamReader (new ByteArrayInputStream(arr),encoding);
    final ByteArrayOutputStream outbs = new ByteArrayOutputStream();
    final Writer out = new OutputStreamWriter (outbs,encoding);
    char[] buffer = new char[6];
    int len;
    while ( (len = in.read(buffer)) >0) {
        out.write (buffer);
    }        
    in.close();
    out.close();
    assertEquals(testString, new String(outbs.toByteArray()));
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:FileEncodingQueryTest.java

示例8: copy

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void copy(InputStream is, OutputStream os) throws IOException {
    try {
        FileUtil.copy(is, os);
    } finally {
        is.close();
        os.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:BackupFacility.java

示例9: copyStringToFileObject

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
/**
 * Copies the given <code>content</code> to the given <code>fo</code>.
 * 
 * @param file the file object to which the given content is copied.
 * @param content the contents to copy.
 */ 
public static final void copyStringToFileObject(FileObject fo, String contents) throws IOException {
    OutputStream os = fo.getOutputStream();
    try {
        InputStream is = new ByteArrayInputStream(contents.getBytes("UTF-8"));
        FileUtil.copy(is, os);
    } finally {
        os.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:TestUtilities.java

示例10: unzip

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static void unzip(InputStream source, FileObject targetFolder) throws IOException {
    //installation
    ZipInputStream zip = new ZipInputStream(source);
    try {
        ZipEntry ent;
        while ((ent = zip.getNextEntry()) != null) {
            if (ent.isDirectory()) {
                FileUtil.createFolder(targetFolder, ent.getName());
            } else {
                FileObject destFile = FileUtil.createData(targetFolder, ent.getName());
                FileLock lock = destFile.lock();
                try {
                    OutputStream out = destFile.getOutputStream(lock);
                    try {
                        FileUtil.copy(zip, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    lock.releaseLock();
                }
            }
        }
    } finally {
        zip.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:JavaFXSampleProjectGenerator.java

示例11: read

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
static Map<String,byte[]> read(File jar) throws IOException {
    JarFile jf = new JarFile(jar, false);
    try {
        Map<String, byte[]> classfiles = new TreeMap<String, byte[]>();
        Enumeration<JarEntry> e = jf.entries();
        while (e.hasMoreElements()) {
            JarEntry entry = e.nextElement();
            String name = entry.getName();
            if (!name.endsWith(".class")) {
                continue;
            }
            String clazz = name.substring(0, name.length() - 6);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(Math.max((int) entry.getSize(), 0));
            InputStream is = jf.getInputStream(entry);
            try {
                FileUtil.copy(is, baos);
            } finally {
                is.close();
            }
            classfiles.put(clazz, baos.toByteArray());
        }
        return classfiles;
    } catch (SecurityException x) {
        throw new IOException(x);
    } finally {
        jf.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ClassDependencyIndexCreator.java

示例12: moduleInfoClz

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
@NonNull
private static Supplier<byte[]> moduleInfoClz(
        @NonNull final Supplier<Pair<Boolean,String>> moduleInfoJava) {
    return () -> {
        try {
            final JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
            final List<String> opts = new ArrayList<>();
            opts.add("-source");        //NOI18N
            opts.add("9");              //NOI18N
            opts.add("-target");        //NOI18N
            opts.add("9");              //NOI18N
            final Pair<Boolean,String> p = moduleInfoJava.get();
            final JavaFileObject moduleInfo = FileObjects.memoryFileObject(
                    "",                 //NOI18N
                    "module-info.java", //NOI18N
                    p.second());
            final JavaFileManager fm = new MemFM(p.first());
            final JavacTask task = (JavacTask) jc.getTask(null, fm, null, opts, null, Collections.singleton(moduleInfo));
            final Iterator<? extends JavaFileObject> res = task.generate().iterator();
            final JavaFileObject fo = res.hasNext() ?
                    res.next() :
                    null;
            if (fo != null) {
                try (InputStream in = fo.openInputStream()) {
                    final ByteArrayOutputStream out = new ByteArrayOutputStream();
                    FileUtil.copy(in, out);
                    out.close();
                    return out.toByteArray();
                }
            } else {
                return null;
            }
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ModuleNamesTest.java

示例13: copyResource

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static void copyResource(URL resource, File file) throws IOException {
    assertNotNull("Resource found", resource);
    file.getParentFile().mkdirs();
    assertTrue("New file " + file + " created", file.createNewFile());
    FileOutputStream os = new FileOutputStream(file);
    InputStream is = resource.openStream();
    FileUtil.copy(is, os);
    is.close();
    os.close();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavacParserTest.java

示例14: assertEquals

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private void assertEquals (String file, InputStream a, InputStream b) throws IOException {
    ByteArrayOutputStream oa = new ByteArrayOutputStream ();
    ByteArrayOutputStream ob = new ByteArrayOutputStream ();
    FileUtil.copy(a, oa);
    FileUtil.copy(b, ob);
    byte[] aa = oa.toByteArray();
    byte[] ab = ob.toByteArray();
    assertEquals ("file: "+ file ,aa.length,ab.length);
    for (int i=0; i< aa.length; i++) {
        assertEquals("file: "+file+ " offset: "+ i, aa[i], ab[i]);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:FastJarTest.java

示例15: createFile

import org.openide.filesystems.FileUtil; //导入方法依赖的package包/类
private static FileObject createFile (final FileObject folder, final String name, final String content) throws IOException {
    final FileObject fo = FileUtil.createData(folder, name);
    final FileLock lock = fo.lock();
    try {
        final OutputStream out = fo.getOutputStream(lock);
        try {
            FileUtil.copy(new ByteArrayInputStream(content.getBytes()), out);
        } finally {
            out.close();
        }
    } finally {
        lock.releaseLock();
    }
    return fo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:SourceUtilsTest.java


注:本文中的org.openide.filesystems.FileUtil.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。