Examples of RandomAccessFile


Examples of java.io.RandomAccessFile

      ListGenerator lg = ListGenerator.getListGenerator(dataSource);
      lg.makeListDirty("Entity");
      lg.makeListDirty("Individual");

      RandomAccessFile ral = new RandomAccessFile(new File(dyn.getFilePath()), "r");

      String readline = "";
      int i = 0;
      //field seperator
      String seperator = dyn.getFieldseprator();

      Vector importList = new Vector();
      Vector headerVector = new Vector();

      String s = "";
      String hasHeader = dyn.getHeaderrow();

      String sFileFieldName = "";

      int headerRow = 0;

      String tabDelimiter = dyn.getFieldseprator();
      String lineDelimiter = dyn.getLineseprator();
      if (tabDelimiter.equals(""))
      {
        tabDelimiter = dyn.getTab();
      }
      if (lineDelimiter.equals(""))
      {
        lineDelimiter = dyn.getLine();
      }

      String headLine = "";
      if (hasHeader.equals("Yes"))
      {
        headLine = ral.readLine();
        headerRow++;
      }

      int iTemp = 0;

      Vector listVector = dyn.getHeadervector();
      int vectorColCounter = 0;

      while ((readline = ral.readLine()) != null)
      {

        String[] lineSeprator = readline.split(lineDelimiter);
        for (int j = 0; j < lineSeprator.length; j++)
        {
View Full Code Here

Examples of java.io.RandomAccessFile

        if (!isWritable()) {
            throw new IOException("No write permission : " + file.getName());
        }

        // create output stream
        final RandomAccessFile raf = new RandomAccessFile(file, "rw");
        raf.setLength(offset);
        raf.seek(offset);

        // The IBM jre needs to have both the stream and the random access file
        // objects closed to actually close the file
        return new FileOutputStream(raf.getFD()) {
            @Override
            public void close() throws IOException {
                super.close();
                raf.close();
            }
        };
    }
View Full Code Here

Examples of java.io.RandomAccessFile

        if (!isReadable()) {
            throw new IOException("No read permission : " + file.getName());
        }

        // move to the appropriate offset and create input stream
        final RandomAccessFile raf = new RandomAccessFile(file, "r");
        raf.seek(offset);

        // The IBM jre needs to have both the stream and the random access file
        // objects closed to actually close the file
        return new FileInputStream(raf.getFD()) {
            @Override
            public void close() throws IOException {
                super.close();
                raf.close();
            }
        };
    }
View Full Code Here

Examples of java.io.RandomAccessFile

            return filepath.substring(0, index);
        }
    }

    public static void truncateFile(File file) {
        final RandomAccessFile raf;
        try {
            raf = new RandomAccessFile(file, "rw");
        } catch (FileNotFoundException fnfe) {
            throw new IllegalStateException(fnfe);
        }
        try {
            raf.setLength(0);
        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
        } finally {
            IOUtils.closeQuietly(raf);
        }
View Full Code Here

Examples of java.io.RandomAccessFile

                      }
                                       
                      Utilities utils = plugin_interface.getUtilities();
                     
                      try{
                        RandomAccessFile raf = new RandomAccessFile(f, "r" );
                       
                        while( !chunks.isEmpty()){
                         
                          long[] chunk = chunks.remove((int)(Math.random()*chunks.size()));
                         
                          final long  position   = chunk[0];
                          final int  size    = (int)chunk[1];
                         
                          raf.seek( position );
                         
                          byte[] buffer = new byte[ size ];
                         
                          raf.read( buffer );
                         
                          int  piece_number   = (int)(position/piece_size);
                          int  piece_offset  = (int)(position % piece_size);
                                             
                          dm.write(
View Full Code Here

Examples of java.io.RandomAccessFile

      File fDescriptions = FileUtil.getUserFile("ipfilter.cache");
      try {
        if (fDescriptions.exists()) {
          fDescriptions.delete();
        }
        rafDescriptions = new RandomAccessFile(fDescriptions, "rw");
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } else if (!enable && rafDescriptions != null) {
View Full Code Here

Examples of java.io.RandomAccessFile

     * @param file the file
     * @param data the data to write
     */
    public static void writeFile(File file, byte[] data) {
        try {
            RandomAccessFile ra = new RandomAccessFile(file, "rw");
            ra.write(data);
            ra.setLength(data.length);
            ra.close();
        } catch (IOException e) {
            throw new RuntimeException("Error writing to file " + file, e);
        }
    }
View Full Code Here

Examples of java.io.RandomAccessFile

     */
    void parse(String baseDir, String className) {
        String fileName = baseDir + "/" + className.replace('.', '/') + ".java";
        current = new ParseState();
        try {
            RandomAccessFile file = new RandomAccessFile(fileName, "r");
            byte[] buff = new byte[(int) file.length()];
            file.readFully(buff);
            source = new String(buff, "UTF-8");
            file.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        source = replaceUnicode(source);
        source = removeRemarks(source);
View Full Code Here

Examples of java.io.RandomAccessFile

    }

    private static void process(String fileName, String find,
            boolean head, boolean tail, long start, int lines,
            boolean quiet) throws IOException {
        RandomAccessFile file = new RandomAccessFile(fileName, "r");
        long length = file.length();
        if (head) {
            file.seek(start);
            list(start, "Head", readLines(file, lines));
        }
        if (find != null) {
            file.seek(start);
            long pos = find(file, find.getBytes(), quiet);
            if (pos >= 0) {
                file.seek(pos);
                list(pos, "Found " + find, readLines(file, lines));
            }
        }
        if (tail) {
            long pos = length - 100L * lines;
            ArrayList<String> list = null;
            while (pos > 0) {
                file.seek(pos);
                list = readLines(file, Integer.MAX_VALUE);
                if (list.size() > lines) {
                    break;
                }
                pos -= 100L * lines;
 
View Full Code Here

Examples of java.io.RandomAccessFile

        return buff.toString();
    }

    private static void writeFile(File file, byte[] data) {
        try {
            RandomAccessFile ra = new RandomAccessFile(file, "rw");
            ra.write(data);
            ra.setLength(data.length);
            ra.close();
        } catch (IOException e) {
            throw new RuntimeException("Error writing to file " + file, e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.