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


Java FileObject.getSize方法代码示例

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


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

示例1: checkMeasuredInternal

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
    public Def checkMeasuredInternal(FileObject file,
            SearchListener listener) {

        if (trivial) {
            return new Def(file, null, null);
        }

        listener.fileContentMatchingStarted(file.getPath());

        long start = System.currentTimeMillis();
        Def def;
        File f = FileUtil.toFile(file);
        if (file.getSize() > SIZE_LIMIT || f == null) {
//            LOG.log(Level.INFO,
//                    "Falling back to default matcher: {0}, {1} kB", //NOI18N
//                    new Object[]{file.getPath(), file.getSize() / 1024});
//            def = getDefaultMatcher().check(file, listener);
            def = checkBig(file, f, listener);
        } else {
            def = checkSmall(file, f, listener);
        }
        totalTime += System.currentTimeMillis() - start;
        return def;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:FastMatcher.java

示例2: compareSize

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Sort folders alphabetically first. Then files, biggest to smallest.
 */
private static int compareSize(Object o1, Object o2) {
    boolean f1 = findFileObject(o1).isFolder();
    boolean f2 = findFileObject(o2).isFolder();

    if (f1 != f2) {
        return f1 ? -1 : 1;
    }

    FileObject fo1 = findFileObject(o1);
    FileObject fo2 = findFileObject(o2);
    long s1 = fo1.getSize();
    long s2 = fo2.getSize();
    if (s1 > s2) {
        return -1;
    } else if (s2 > s1) {
        return 1;
    } else {
        return fo1.getNameExt().compareTo(fo2.getNameExt());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FolderComparator.java

示例3: sniff

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Go ahead and retrieve a print or null
 */
protected Smell sniff(FileObject fo) {

    if (fo == null) return null;
    
    if (fo.equals(lastFileObject)) return print;
    
    if (fo.isValid() == false) return null;

    if (fo.getSize() == 0) return null;
    
    print = new Smell();
    errors = 0;
    parse(fo);
    if (this.state == ERROR) {
        return null;
    }
    
    lastFileObject = fo;
    return print;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:XMLMIMEComponent.java

示例4: canDecodeFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private boolean canDecodeFile(FileObject fo, String encoding) {
    CharsetDecoder decoder = Charset.forName(encoding).newDecoder().onUnmappableCharacter(CodingErrorAction.REPORT).onMalformedInput(CodingErrorAction.REPORT);
    try {
        BufferedInputStream bis = new BufferedInputStream(fo.getInputStream());
        //I probably have to create such big buffer since I am not sure
        //how to cut the file to smaller byte arrays so it cannot happen
        //that an encoded character is divided by the arrays border.
        //In such case it might happen that the method woult return
        //incorrect value.
        byte[] buffer = new byte[(int) fo.getSize()];
        bis.read(buffer);
        bis.close();
        decoder.decode(ByteBuffer.wrap(buffer));
        return true;
    } catch (CharacterCodingException ex) {
        //return false
    } catch (IOException ioe) {
        Logger.getLogger("global").log(Level.WARNING, "Error during charset verification", ioe);
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:HtmlEditorSupport.java

示例5: TLDataObject

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public TLDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
            getCookieSet().assign(SaveCookie.class, saveDB);
            setModified(true);

    if (pf.getSize() > 0) {
        database = getDBFromFile(pf);
    } else {
        database = new TLDatabase();
    }

    CookieSet cookies = getCookieSet();
    cookies.assign(TLDatabase.class, database);
    cookies.add(new TLOpenSupport(this.getPrimaryEntry()));


    cookies.assign(Node.class, this.getNodeDelegate());

    // Set modified if current time of db changes
    database.addDBListener(changeListener);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:22,代码来源:TLDataObject.java

示例6: getImageData

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Gets image data for the image object.
 * @return the image data
 * @deprecated use getImage() instead
 */
private byte[] getImageData() {
    try {
        FileObject fo = getPrimaryFile();
        byte[] imageData = new byte[(int)fo.getSize()];
        BufferedInputStream in = new BufferedInputStream(fo.getInputStream());
        in.read(imageData, 0, (int)fo.getSize());
        in.close();
        return imageData; 
    } catch(IOException ioe) {
        return new byte[0];
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ImageDataObject.java

示例7: big

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@NbBundle.Messages({
    "TTL_ContextView_showBigFile=Show Big File?",
    "# {0} - file name",
    "# {1} - file size in kilobytes",
    "MSG_ContextView_showBigFile=File {0} is quite big ({1} kB).\n"
    + "Showing it can cause memory and performance problems.\n"
    + "Do you want to show content of this file?",
    "LBL_ContextView_Show=Show",
    "LBL_ContextView_Skip=Do Not Show",
    "LBL_ContextView_ApplyAll=Apply to all big files"
})
private void approveFetchingOfBigFile(final MatchingObject mo,
        final int partIndex) {
    FileObject fo = mo.getFileObject();
    long fileSize = fo.getSize() / 1024;
    JButton showButton = new JButton(Bundle.LBL_ContextView_Show());
    JButton skipButton = new JButton(Bundle.LBL_ContextView_Skip());
    JCheckBox all = new JCheckBox(Bundle.LBL_ContextView_ApplyAll());
    all.setSelected(approveApplyToAllSelected);
    JPanel allPanel = new JPanel();
    allPanel.add(all); //Add to panel not to be handled as standard button.
    NotifyDescriptor nd = new NotifyDescriptor(
            Bundle.MSG_ContextView_showBigFile(
            fo.getNameExt(), fileSize),
            Bundle.TTL_ContextView_showBigFile(),
            NotifyDescriptor.YES_NO_OPTION,
            NotifyDescriptor.WARNING_MESSAGE,
            new Object[]{skipButton, showButton},
            lastApproveOption ? showButton : skipButton);
    nd.setAdditionalOptions(new Object[]{allPanel});
    DialogDisplayer.getDefault().notify(nd);
    boolean app = nd.getValue() == showButton;
    APPROVED_FILES.put(fo, app);
    if (all.isSelected()) {
        allApproved = app;
    }
    approveApplyToAllSelected = all.isSelected();
    lastApproveOption = app;
    displayFile(mo, partIndex);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:ContextView.java

示例8: getFreshInvalidityStatus

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Check validity status of this item.
 * 
 * @return  an invalidity status of this item if it is invalid,
 *          or {@code null} if this item is valid
 * @author  Tim Boudreau
 * @author  Marian Petras
 */
private InvalidityStatus getFreshInvalidityStatus() {
    log(FINER, "getInvalidityStatus()");                            //NOI18N
    FileObject f = getFileObject();
    if (!f.isValid()) {
        log(FINEST, " - DELETED");            
        return InvalidityStatus.DELETED;
    }
    if (f.isFolder()) {
        log(FINEST, " - BECAME_DIR");            
        return InvalidityStatus.BECAME_DIR;
    }
    
    long stamp = f.lastModified().getTime();
    if ((!refreshed && stamp > resultModel.getStartTime())
            || (refreshed && stamp > timestamp)) {
        log(SEVERE, "file's timestamp changed since start of the search");
        if (LOG.isLoggable(FINEST)) {
            final java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.setTimeInMillis(stamp);
            log(FINEST, " - file stamp:           " + stamp + " (" + cal.getTime() + ')');
            cal.setTimeInMillis(resultModel.getStartTime());
            log(FINEST, " - result model created: " + resultModel.getStartTime() + " (" + cal.getTime() + ')');
        }            
        return InvalidityStatus.CHANGED;
    }
    
    if (f.getSize() > Integer.MAX_VALUE) {            
        return InvalidityStatus.TOO_BIG;
    }
    
    if (!f.canRead()) {           
        return InvalidityStatus.CANT_READ;
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:MatchingObject.java

示例9: testLayerHandle

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testLayerHandle() throws Exception {
    NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module");
    LayerHandle handle = LayerHandle.forProject(project);
    FileObject expectedLayerXML = project.getProjectDirectory().getFileObject("src/org/example/module/resources/layer.xml");
    assertNotNull(expectedLayerXML);
    FileObject layerXML = handle.getLayerFile();
    assertNotNull("layer.xml already exists", layerXML);
    assertEquals("right layer file", expectedLayerXML, layerXML);
    FileSystem fs = handle.layer(true);
    assertEquals("initially empty", 0, fs.getRoot().getChildren().length);
    long initialSize = layerXML.getSize();
    fs.getRoot().createData("foo");
    assertEquals("not saved yet", initialSize, layerXML.getSize());
    fs = handle.layer(true);
    assertNotNull("still have in-memory mods", fs.findResource("foo"));
    fs.getRoot().createData("bar");
    handle.save();
    assertTrue("now it is saved", layerXML.getSize() > initialSize);
    String xml =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.2//EN\" \"http://www.netbeans.org/dtds/filesystem-1_2.dtd\">\n" +
            "<filesystem>\n" +
            "    <file name=\"bar\"/>\n" +
            "    <file name=\"foo\"/>\n" +
            "</filesystem>\n";
    assertEquals("right contents too", xml, TestBase.slurp(layerXML));
    // XXX test that nbres: file contents work
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:LayerHandleTest.java

示例10: IconFileItem

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
IconFileItem(FileObject file) {
    this.file = file;
    try {
        try {
            Image image = (file.getSize() < SIZE_LIMIT) ? ImageIO.read(file.getURL()) : null;
            icon = (image != null) ? new ImageIcon(image) : null;
        } catch (IllegalArgumentException iaex) { // Issue 178906
            Logger.getLogger(CustomIconEditor.class.getName()).log(Level.INFO, null, iaex);
            icon = new ImageIcon(file.getURL());
        }
    } catch (IOException ex) {
        Logger.getLogger(CustomIconEditor.class.getName()).log(Level.WARNING, null, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CustomIconEditor.java

示例11: inputStream

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Obtains the input stream.
* @exception IOException if an I/O error occurs
*/
public InputStream inputStream() throws IOException {
    final FileObject fo = getFileImpl ();
    boolean warned = warnedFiles.contains(fo);
    long size = -1;
    if (!warned && (size = fo.getSize ()) > BIG_FILE_THRESHOLD_MB) {
        throw new ME (size);
    } else if (!sentBigFileInfo && ((size >= 0) ? size : fo.getSize()) > BIG_FILE_THRESHOLD_MB) {
        // warned can contain any file after deserialization
        notifyBigFileLoaded();
    }
    initCanWrite(false);
    InputStream is = getFileImpl ().getInputStream ();
    return is;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DataEditorSupport.java

示例12: getDocument

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Load the document for the given fileObject.
 * @param fileObject the file whose document we want to obtain
 * @param openIfNecessary If true, block if necessary to open the document. If false, will only return the
 *    document if it is already open.
 * @param skipLarge If true, check the file size, and if the file is really large (defined by
 *    openide.loaders), then skip it (otherwise we could end up with a large file warning).
 * @return
 */
public static BaseDocument getDocument(FileObject fileObject, boolean openIfNecessary, boolean skipLarge) {
    if (skipLarge) {
        // Make sure we're not dealing with a huge file!
        // Causes issues like 132306
        // openide.loaders/src/org/openide/text/DataEditorSupport.java
        // has an Env#inputStream method which posts a warning to the user
        // if the file is greater than 1Mb...
        //SG_ObjectIsTooBig=The file {1} seems to be too large ({2,choice,0#{2}b|1024#{3} Kb|1100000#{4} Mb|1100000000#{5} Gb}) to safely open. \n\
        //  Opening the file could cause OutOfMemoryError, which would make the IDE unusable. Do you really want to open it?

        // Apparently there is a way to handle this
        // (see issue http://www.netbeans.org/issues/show_bug.cgi?id=148702 )
        // but for many cases, the user probably doesn't want really large files as indicated
        // by the skipLarge parameter).
        if (fileObject.getSize () > 1024 * 1024) {
            return null;
        }
    }

    try {
        EditorCookie ec = fileObject.isValid() ? DataLoadersBridge.getDefault().getCookie(fileObject, EditorCookie.class) : null;
        if (ec != null) {
            if (openIfNecessary) {
                try {
                    return (BaseDocument) ec.openDocument();
                } catch (UserQuestionException uqe) {
                    uqe.confirmed();
                    return (BaseDocument) ec.openDocument();
                }
            } else {
                return (BaseDocument) ec.getDocument();
            }
        }
    } catch (IOException ex) {
        LOG.log(Level.WARNING, null, ex);
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:GsfUtilities.java

示例13: idForFile

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Traverses shadow files to origin.
 * Returns impl class name if that is obvious (common for SystemAction's);
 * else just returns file path (usual for more modern registrations).
 */
private static String idForFile(FileObject f) {
    if (f.hasExt(SHADOW_EXT)) {
        String path = (String) f.getAttribute("originalFile");
        if (path != null && f.getSize() == 0) {
            f = FileUtil.getConfigFile(path);
            if (f == null) {
                return path; // #169887: some race condition with layer init?
            }
        } else {
            try {
                DataObject d = DataObject.find(f);
                if (d instanceof DataShadow) {
                    f = ((DataShadow) d).getOriginal().getPrimaryFile();
                }
            } catch (DataObjectNotFoundException x) {
                LOG.log(Level.FINE, f.getPath(), x);
            }
        }
    }
    // Cannot actually load instanceCreate methodvalue=... attribute; just want to see if it is there.
    if (f.hasExt("instance") && !Collections.list(f.getAttributes()).contains("instanceCreate")) {
        String clazz = (String) f.getAttribute("instanceClass");
        if (clazz != null) {
            return clazz;
        } else {
            return f.getName().replace('-', '.');
        }
    }
    return f.getPath();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:NbKeymap.java

示例14: testSelfProfileToStream

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Test
public void testSelfProfileToStream() throws Exception {
    Sampler sampler = Sampler.createManualSampler("testprofile");
    assertTrue("sampler instance", sampler != null);

    sampler.start();
    Thread.sleep(1000);
    assertSamplerThread("sampler-testprofile shall be there", true);

    FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("slow.nps");
    OutputStream os = fo.getOutputStream();
    DataOutputStream dos = new DataOutputStream(os);
    sampler.stopAndWriteTo(dos);
    dos.close();

    if (fo.getSize() < 100) {
        fail("The file shall have real content: " + fo.getSize());
    }

    DataObject dataObject = DataObject.find(fo);
    assertEquals("Nps DataObject", NpsDataObject.class, dataObject.getClass());
    OpenCookie oc = dataObject.getLookup().lookup(OpenCookie.class);
    assertNotNull("Open cookie exists", oc);

    CharSequence log = Log.enable("", Level.WARNING);
    oc.open();

    if (log.length() > 0) {
        fail("There shall be no warnings:\n" + log);
    }

    assertSamplerThread("no sampler- thread shall be there", false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:SelfSamplerActionTest.java

示例15: getCrc32

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Find (maybe cached) CRC for a file, using a preexisting input stream (not closed by this method). */
private static String getCrc32(InputStream is, FileObject fo) throws IOException {
    URL u = fo.toURL();
    fo.refresh(); // in case was written on disk and we did not notice yet...
    long footprint = fo.lastModified().getTime() ^ fo.getSize();
    String crc = findCachedCrc32(u, footprint);
    if (crc == null) {
        crc = computeCrc32(is);
        cacheCrc32(crc, u, footprint);
    }
    return crc;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:GeneratedFilesHelper.java


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