Exemplo n.º 1
0
        public void Test_FileParentFile()
        {
            String expected = System.Reflection.Assembly.GetAssembly(typeof(java.lang.SystemJ)).Location;

            expected = expected.Substring(0, expected.Length - "/VampireApi.dll".Length);

            java.io.File runtimeDll = new java.io.File(System.Reflection.Assembly.GetAssembly(typeof(java.lang.SystemJ)).Location);
            String       actually   = runtimeDll.getParentFile().toString();

            Assert.AreEqual(expected, actually);
        }
Exemplo n.º 2
0
        static java.util.Properties loadFilePrefsImpl(java.io.File file)
        {
            Properties result = new Properties();

            if (!file.exists())
            {
                file.getParentFile().mkdirs();
                return(result);
            }

            if (file.canRead())
            {
                java.io.InputStream        inJ   = null;
                java.nio.channels.FileLock lockJ = null;
                try {
                    java.io.FileInputStream istream = new java.io.FileInputStream(file);
                    inJ = new java.io.BufferedInputStream(istream);
                    java.nio.channels.FileChannel channel = istream.getChannel();
                    lockJ = channel.lockJ(0L, java.lang.Long.MAX_VALUE, true);
                    org.w3c.dom.Document doc     = builder.parse(inJ);
                    org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(doc
                                                                                            .getDocumentElement(), "entry"); //$NON-NLS-1$
                    int length = entries.getLength();
                    for (int i = 0; i < length; i++)
                    {
                        org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item(i);
                        String key   = node.getAttribute("key");                        //$NON-NLS-1$
                        String value = node.getAttribute("value");                      //$NON-NLS-1$
                        result.setProperty(key, value);
                    }
                    return(result);
                } catch (java.io.IOException e) {
                } catch (org.xml.sax.SAXException e) {
                } catch (javax.xml.transform.TransformerException e) {
                    // transform shouldn't fail for xpath call
                    throw new java.lang.AssertionError(e);
                } finally {
                    releaseQuietly(lockJ);
                    closeQuietly(inJ);
                }
            }
            else
            {
                file.delete();
            }
            return(result);
        }