當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。