コード例 #1
0
        public void Test_FileHidden()
        {
            switch (System.Environment.OSVersion.Platform)
            {
            case PlatformID.Unix:
            case PlatformID.MacOSX:
                String name = java.lang.SystemJ.getProperty("java.io.tmpdir") + ".VampireApi.secret";

                java.io.File hidden = new java.io.File(name);
                if (!hidden.exists())
                {
                    String content = "secret=geheimnis";
                    byte[]  value  = System.Text.Encoding.GetEncoding("utf-8").GetBytes(content);

                    java.io.FileOutputStream fos = new java.io.FileOutputStream(name);
                    fos.write(value, 0, value.Length);
                    fos.flush();
                    fos.close();
                }
                Assert.True(new java.io.File(name).exists(), "java.io.File.exists() found not file " + name);
                Assert.True(hidden.isHidden(), "File " + hidden.toString() + " should be hidden");
                break;

            default:
                Assert.Warn("Test_FileHidden not implemented for this platform");
                break;
            }
        }
コード例 #2
0
ファイル: XMLParser.cs プロジェクト: minam365/JavApi
 static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs)
 {        //throws IOException {
     java.io.BufferedWriter     outJ  = null;
     java.nio.channels.FileLock lockJ = null;
     try {
         java.io.FileOutputStream ostream = new java.io.FileOutputStream(file);
         outJ = new java.io.BufferedWriter(new java.io.OutputStreamWriter(ostream, "UTF-8"));                   //$NON-NLS-1$
         java.nio.channels.FileChannel channel = ostream.getChannel();
         lockJ = channel.lockJ();
         outJ.write(HEADER);
         outJ.newLine();
         outJ.write(FILE_PREFS);
         outJ.newLine();
         if (prefs.size() == 0)
         {
             exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, outJ);
         }
         else
         {
             String[] keys = prefs.keySet()
                             .toArray(new String[prefs.size()]);
             int      length = keys.Length;
             String[] values = new String[length];
             for (int i = 0; i < length; i++)
             {
                 values [i] = prefs.getProperty(keys [i]);
             }
             exportEntries(keys, values, outJ);
         }
         outJ.flush();
     } finally {
         releaseQuietly(lockJ);
         closeQuietly(outJ);
     }
 }
コード例 #3
0
        public void Test_WriteSimpleFile()
        {
            String name    = java.lang.SystemJ.getProperty("java.io.tmpdir") + "VampireApi4U.html";
            String content = "<html><body><h1>Just Another Vampire Api 4 .net, aka Java4.net</h1></body></html>";

            byte[]  value = System.Text.Encoding.GetEncoding("utf-8").GetBytes(content);

            java.io.FileOutputStream fos = new java.io.FileOutputStream(name);
            fos.write(value, 0, value.Length);
            fos.flush();
            fos.close();

            Assert.False(new java.io.File(java.lang.SystemJ.getProperty("java.io.tmpdir") + "not.exist").exists(), "java.io.File.exists() found not existing file");
            Assert.True(new java.io.File(name).exists(), "write simple file error");
            Assert.AreEqual(81, new java.io.File(name).length(), "content size of file unexpected");
        }
コード例 #4
0
 static void Main()
 {
     String[] pangramm = {
         "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux?", // de
         "The quick brown fox jumps over the lazy dog",              // en
         "Portez ce vieux whisky au juge blond qui fume",            // fr
         "Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф",             // ru
         "Chwyć małżonkę, strój bądź pleśń z fugi.",                 // pl
         "V kožuščku hudobnega fanta stopiclja mizar in kliče.",     // sl
         "以呂波耳本へ止 千利奴流乎和加 餘多連曽津祢那 良牟有為能於久 耶万計不己衣天 阿佐伎喩女美之 恵比毛勢須", // jp
                          };
     java.io.FileOutputStream fos = new java.io.FileOutputStream("c:/temp/sample.txt");
     foreach (String p in pangramm) {
         fos.write(p.getBytes());
     }
     fos.flush();
     fos.close();
 }
コード例 #5
0
        /**
         * Creates a table given the name and a vector of
         * column definition (tsColumn) arrays.<br>
         *
         * @param table_name the name of the table
         * @param v a Vector containing arrays of column definitions.
         * @see tinySQL#CreateTable
         */
        internal override void CreateTable(String table_name, java.util.Vector <Object> v)
        {//throws IOException, tinySQLException {
            // make the data directory, if it needs to be make
            //
            mkDataDirectory();

            // perform an implicit drop table.
            //
            DropTable(table_name);

            // create the table definition file
            //
            java.io.FileOutputStream fdef =
                new java.io.FileOutputStream(dataDir + "/" + table_name + ".def");

            // open it as a DataOutputStream
            //
            java.io.DataOutputStream def = new java.io.DataOutputStream(fdef);

            // write out the column definition for the _DELETED column
            //
            def.writeBytes("CHAR|_DELETED|1\n");

            // write out the rest of the columns' definition. The
            // definition consists of datatype, column name, and
            // size delimited by a pipe symbol
            //
            for (int i = 0; i < v.size(); i++)
            {
                def.writeBytes(((TsColumn)v.elementAt(i)).type + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).name + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).size + "\n");
            }

            // flush the DataOutputStream and jiggle the handle
            //
            def.flush();

            // close the file
            //
            fdef.close();
        }
コード例 #6
0
 static void Main()
 {
     String[] pangramm =
     {
         "Welch fieser Katzentyp quält da süße Vögel bloß zum Jux?", // de
         "The quick brown fox jumps over the lazy dog",              // en
         "Portez ce vieux whisky au juge blond qui fume",            // fr
         "Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф",             // ru
         "Chwyć małżonkę, strój bądź pleśń z fugi.",                 // pl
         "V kožuščku hudobnega fanta stopiclja mizar in kliče.",     // sl
         "以呂波耳本へ止 千利奴流乎和加 餘多連曽津祢那 良牟有為能於久 耶万計不己衣天 阿佐伎喩女美之 恵比毛勢須",    // jp
     };
     java.io.FileOutputStream fos = new java.io.FileOutputStream("c:/temp/sample.txt");
     foreach (String p in pangramm)
     {
         fos.write(p.getBytes());
     }
     fos.flush();
     fos.close();
 }
コード例 #7
0
        public void extractBZip2Test()
        {
            int buffersize = 4096;

            java.io.File bz2 = new java.io.File("C:\\Develop\\Projekte\\J.net\\JavApi Test\\org\\apache\\commons\\compress\\bzip2\\ASL2.bz2");
            java.lang.SystemJ.outJ.println(bz2.toString());
            java.io.FileInputStream     fin  = new java.io.FileInputStream(bz2);
            java.io.BufferedInputStream inJ  = new java.io.BufferedInputStream(fin);
            java.io.FileOutputStream    outJ = new java.io.FileOutputStream("C:\\Develop\\Projekte\\J.net\\JavApi Commons Compress (Apache Port)\\archive.tar");
            org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream bzIn = new org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream(inJ);
            byte[] buffer = new byte[buffersize];
            int    n      = 0;

            while (-1 != (n = bzIn.read(buffer)))
            {
                outJ.write(buffer, 0, n);
            }
            outJ.close();
            bzIn.close();
        }
コード例 #8
0
 /**
  * Creates a new ZIP OutputStream writing to a File.  Will use
  * random access if possible.
  * @param file the file to zip to
  * @throws IOException on error
  */
 public ZipArchiveOutputStream(java.io.File file) //throws IOException
 {
     java.io.OutputStream     o    = null;
     java.io.RandomAccessFile _raf = null;
     try {
         _raf = new java.io.RandomAccessFile(file, "rw");
         _raf.setLength(0);
     } catch (java.io.IOException) {
         if (_raf != null)
         {
             try {
                 _raf.close();
             } catch (java.io.IOException) {
                 // ignore
             }
             _raf = null;
         }
         o = new java.io.FileOutputStream(file);
     }
     outJ = o;
     raf  = _raf;
 }
コード例 #9
0
        private void initOutputFiles()//throws FileNotFoundException, IOException {
        {
            while (true)
            {
                // try to find a unique file which is not locked by other process
                uniqueID++;
                // FIXME: improve performance here
                for (int generation = 0; generation < count; generation++)
                {
                    // cache all file names for rotation use
                    files[generation] = new java.io.File(parseFileName(generation));
                }
                fileName = files[0].getAbsolutePath();
                lock (allLocks) {
                    /*
                     * if current process has held lock for this fileName continue
                     * to find next file
                     */
                    if (null != allLocks.get(fileName))
                    {
                        continue;
                    }
                    if (files[0].exists() &&
                        (!append || files[0].length() >= limit))
                    {
                        for (int i = count - 1; i > 0; i--)
                        {
                            if (files[i].exists())
                            {
                                files[i].delete();
                            }
                            files[i - 1].renameTo(files[i]);
                        }
                    }
                    java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName
                                                                                       + LCK_EXT);
                    java.nio.channels.FileChannel channel = fileStream.getChannel();

                    /*
                     * if lock is unsupported and IOException thrown, just let the
                     * IOException throws out and exit otherwise it will go into an
                     * undead cycle
                     */
                    lockJ = channel.tryLock();
                    if (null == lockJ)
                    {
                        try {
                            fileStream.close();
                        } catch (Exception e) {
                            // ignore
                        }
                        continue;
                    }
                    allLocks.put(fileName, lockJ);
                    break;
                }
            }
            output = new MeasureOutputStream(new java.io.BufferedOutputStream(
                                                 new java.io.FileOutputStream(fileName, append)), files[0].length());
            setOutputStream(output);
        }
コード例 #10
0
ファイル: FileHandler.cs プロジェクト: sailesh341/JavApi
 private void initOutputFiles()
 {
     //throws FileNotFoundException, IOException {
     while (true) {
     // try to find a unique file which is not locked by other process
     uniqueID++;
     // FIXME: improve performance here
     for (int generation = 0; generation < count; generation++) {
         // cache all file names for rotation use
         files[generation] = new java.io.File(parseFileName(generation));
     }
     fileName = files[0].getAbsolutePath();
     lock (allLocks) {
         /*
          * if current process has held lock for this fileName continue
          * to find next file
          */
         if (null != allLocks.get(fileName)) {
             continue;
         }
         if (files[0].exists()
                 && (!append || files[0].length() >= limit)) {
             for (int i = count - 1; i > 0; i--) {
                 if (files[i].exists()) {
                     files[i].delete();
                 }
                 files[i - 1].renameTo(files[i]);
             }
         }
         java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName
                 + LCK_EXT);
         java.nio.channels.FileChannel channel = fileStream.getChannel();
         /*
          * if lock is unsupported and IOException thrown, just let the
          * IOException throws out and exit otherwise it will go into an
          * undead cycle
          */
         lockJ = channel.tryLock();
         if (null == lockJ) {
             try {
                 fileStream.close();
             } catch (Exception e) {
                 // ignore
             }
             continue;
         }
         allLocks.put(fileName, lockJ);
         break;
     }
     }
     output = new MeasureOutputStream(new java.io.BufferedOutputStream(
         new java.io.FileOutputStream(fileName, append)), files[0].length());
     setOutputStream(output);
 }
コード例 #11
0
ファイル: XMLParser.cs プロジェクト: sailesh341/JavApi
 static void flushFilePrefsImpl(java.io.File file, java.util.Properties prefs)
 {
     //throws IOException {
     java.io.BufferedWriter outJ = null;
     java.nio.channels.FileLock lockJ = null;
     try {
         java.io.FileOutputStream ostream = new java.io.FileOutputStream (file);
         outJ = new java.io.BufferedWriter (new java.io.OutputStreamWriter (ostream, "UTF-8")); //$NON-NLS-1$
         java.nio.channels.FileChannel channel = ostream.getChannel ();
         lockJ = channel.lockJ ();
         outJ.write (HEADER);
         outJ.newLine ();
         outJ.write (FILE_PREFS);
         outJ.newLine ();
         if (prefs.size () == 0) {
             exportEntries (EMPTY_SARRAY, EMPTY_SARRAY, outJ);
         } else {
             String[] keys = prefs.keySet ()
                 .toArray (new String[prefs.size ()]);
             int length = keys.Length;
             String[] values = new String[length];
             for (int i = 0; i < length; i++) {
                 values [i] = prefs.getProperty (keys [i]);
             }
             exportEntries (keys, values, outJ);
         }
         outJ.flush ();
     } finally {
         releaseQuietly (lockJ);
         closeQuietly (outJ);
     }
 }