Package java.io

Examples of java.io.RandomAccessFile


    //setHeader("Etag", HttpUtil.getEtag(file));
    setHeader("Content-Length", String.valueOf(file.length()));
    long bytesWritten = 0;
    flush(); // write initial line + headers
    try {
      bytesWritten = new RandomAccessFile(file, "r").getChannel().transferTo(0, file.length(), (SocketChannel) key.channel());
      logger.debug("sent file, bytes sent: {}", bytesWritten);
    } catch (IOException e) {
      logger.error("Error writing (static file) response: {}", e.getMessage());
    }
    return bytesWritten;
View Full Code Here


      //  Search for old log file, then apply all committed operation,
      // finally cleans it.
      File logFilePN = new File(dir, "log");
      if ((logFilePN.exists()) && (logFilePN.length() > 0)) {
        logFile = new RandomAccessFile(logFilePN, "r");
        try {
          int optype = logFile.read();
          while (optype == Operation.COMMIT) {
            String dirName;
            String name;

            optype = logFile.read();
            while ((optype == Operation.CREATE) ||
                   (optype == Operation.SAVE) ||
                   (optype == Operation.DELETE)) {
              //  Gets all operations of one committed transaction then
              // adds them to specified log.
              dirName = logFile.readUTF();
              if (dirName.length() == 0) dirName = null;
              name = logFile.readUTF();

              Object key = OperationKey.newKey(dirName, name);

              if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
                logmon.log(BasicLevel.DEBUG,
                           "NTransaction.init(), OPERATION=" + optype + ", " + name);

              Operation op = null;
              if ((optype == Operation.SAVE) || (optype == Operation.CREATE)) {
                byte buf[] = new byte[logFile.readInt()];
                logFile.readFully(buf);
                op = Operation.alloc(optype, dirName, name, buf);
                Operation old = (Operation) log.put(key, op);
                if (old != null) old.free();
              } else {
                // Operation.DELETE
                op = Operation.alloc(optype, dirName, name);
                Operation old = (Operation) log.put(key, op);
                if (old != null) {
                  if (old.type == Operation.CREATE) op.type = Operation.NOOP;
                  old.free();
                }
              }
             
              optype = logFile.read();
            }
            if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
              logmon.log(BasicLevel.DEBUG,
                         "NTransaction.init(), COMMIT=" + optype);
          }

          if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
            logmon.log(BasicLevel.DEBUG,
                       "NTransaction.init(), END=" + optype + ", " +
                       logFile.getFilePointer());

          if (optype != Operation.END)
            throw new IOException("Corrupted transaction log");
        } catch (IOException exc) {
          throw exc;
        } finally {
          logFile.close();
        }

        logFile = new RandomAccessFile(logFilePN, mode);
        garbage();
      } else {
        logFile = new RandomAccessFile(logFilePN, mode);
        logFile.setLength(MaxLogFileSize);

        current = 1;
        // Cleans log file
        logFile.seek(0);
View Full Code Here

      FileOutputStream fos = new FileOutputStream(file);
      fos.write(content);
      fos.getFD().sync();
      fos.close();
    } else {
      RandomAccessFile raf = new RandomAccessFile(file, "rwd");
      raf.write(content);
      raf.close();                   
    }

    nbsaved += 1;
  }
View Full Code Here

    Operation.initPool(LogThresholdOperation);

    // Read the log, then...
    int oldPhase = FREE;

    logFile = new RandomAccessFile(new File(dir, LOG), "rw");
    log = new Hashtable();
    if (logFile.length() != 0) {
      logFile.seek(0L);
      oldPhase = logFile.readInt();
View Full Code Here

        if(fileChannel == null) {
            File file = new File(filePath);
            if(!file.exists()) {
                throw new IllegalStateException("file not exists: " + filePath);
            }
            final RandomAccessFile raf;
            try {
                raf = new RandomAccessFile(file, "r");
            } catch (FileNotFoundException e) {
                throw new IllegalStateException(e);
            }
            fileChannel = raf.getChannel();
            fdCacheMap.put(filePath, fileChannel);
        }
        long count = request.endOffset - request.startOffset;
        long position = request.startOffset;
View Full Code Here

        FileChannel fileChannel = fdCacheMap.get(filePath);
        if(fileChannel == null) {
            if(!dataFile.exists()) {
                throw new IllegalStateException("file not exists: " + filePath);
            }
            final RandomAccessFile raf;
            try {
                raf = new RandomAccessFile(dataFile, "r");
            } catch (FileNotFoundException e) {
                throw new IllegalStateException(e);
            }
            fileChannel = raf.getChannel();
            fdCacheMap.put(filePath, fileChannel);
        }

        for(int i = 0; i < size; i++) {
            final long offset = offsets[i];
View Full Code Here

            if (installedPlugin != null && (installedPlugin.getInfo().getVersion().compareTo(version1) > 0 || (installedPlugin.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) {
              alreadyInstalled.append(installedPlugin.getInfo().getName()).append('\n');
            } else if (service != null && (service.getInfo().getVersion().compareTo(version1) > 0 || (service.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) {
              alreadyInstalled.append(service.getInfo().getName()).append('\n');
            } else {
              RandomAccessFile write = new RandomAccessFile(tmpFile, "rw");

              String versionString = Integer.toString(version1.getMajor()) + '.' + (version1.getMinor() / 10) + (version1.getMinor() % 10)
                  + '.' + version1.getSubMinor();

              write.seek(write.length());

              write.writeBytes("[plugin:" + pluginName + "]\n");
              write.writeBytes("name_en=" + pluginName + "\n");
              write.writeBytes("filename=" + jarFile.getName() + "\n");
              write.writeBytes("version=" + versionString + "\n");
              write.writeBytes("stable=" + version1.isStable() + "\n");
              write.writeBytes("download=" + jarFile.toURI().toURL() + "\n");
              write.writeBytes("category=unknown\n");

              write.close();

            }
          } catch (Exception e) {
            notCompatiblePlugins.append(jarFile.getName()).append("\n");
          }
View Full Code Here

   */
  private static class LinkFile {
    private String mTarget;

    private LinkFile(File linkFile, File target, File icon, int iconIndex) throws IOException {
      RandomAccessFile write = new RandomAccessFile(linkFile, "rw");

      write.getChannel().truncate(0);

      write.writeBytes("[InternetShortcut]\r\n");
      write.writeBytes("URL=" + target.getAbsoluteFile().toURI().toURL() + "\r\n");
      write.writeBytes("WorkingDirectory=" + target.getParent());

      if(icon != null && icon.isFile()) {
        write.writeBytes("\r\nIconFile=" + icon.getAbsolutePath() + "\r\n");
        write.writeBytes("IconIndex=" + iconIndex);
      }

      write.close();
    }
View Full Code Here

    /**
     * @param linkFile The file the link is stored in.
     * @throws IOException Thrown if something went wrong.
     */
    public LinkFile(File linkFile) throws IOException {
      RandomAccessFile read = new RandomAccessFile(linkFile,"r");

      String line = null;

      while((line = read.readLine()) != null) {
        if(line.startsWith("URL")) {
          mTarget = line.substring(line.indexOf(":/")+2);
        }
      }

      read.close();
    }
View Full Code Here

      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

TOP

Related Classes of java.io.RandomAccessFile

Copyright © 2018 www.massapicom. 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.