예제 #1
1
  public double saveBinaryFileWithBuffer() {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithBuffer.bin");
    DataOutputStream outPut = null;
    DataInputStream inPut = null;
    FileOutputStream fileOut = null;
    FileInputStream fileIn = null;
    BufferedInputStream buffInput = null;
    BufferedOutputStream buffOut = null;
    try {
      fileOut = new FileOutputStream(file);
      buffOut = new BufferedOutputStream(fileOut);
      outPut = new DataOutputStream(buffOut);
      for (Edge e : edges) {
        outPut.writeDouble(e.X1);
        outPut.writeDouble(e.Y1);
        outPut.writeDouble(e.X2);
        outPut.writeDouble(e.Y2);
        outPut.writeDouble(e.color.getRed());
        outPut.writeDouble(e.color.getGreen());
        outPut.writeDouble(e.color.getBlue());
        outPut.flush();
      }
      outPut.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    // Now read every edge from the file and draw it.
    try {
      fileIn = new FileInputStream(file);
      buffInput = new BufferedInputStream(fileIn);
      inPut = new DataInputStream(buffInput);

      if (inPut.available() > 0) {
        while (inPut.available() > 0) {
          double X1 = inPut.readDouble();
          double Y1 = inPut.readDouble();
          double X2 = inPut.readDouble();
          double Y2 = inPut.readDouble();
          double red = inPut.readDouble();
          double green = inPut.readDouble();
          double blue = inPut.readDouble();

          Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
          drawEdge(e);
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return System.nanoTime() - time;
  }
 /**
  * Tries to lock all local shards for the given index. If any of the shard locks can't be acquired
  * an {@link LockObtainFailedException} is thrown and all previously acquired locks are released.
  *
  * @param index the index to lock shards for
  * @param lockTimeoutMS how long to wait for acquiring the indices shard locks
  * @return the {@link ShardLock} instances for this index.
  * @throws IOException if an IOException occurs.
  */
 public List<ShardLock> lockAllForIndex(
     Index index, @IndexSettings Settings settings, long lockTimeoutMS) throws IOException {
   final Integer numShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null);
   if (numShards == null || numShards <= 0) {
     throw new IllegalArgumentException("settings must contain a non-null > 0 number of shards");
   }
   logger.trace("locking all shards for index {} - [{}]", index, numShards);
   List<ShardLock> allLocks = new ArrayList<>(numShards);
   boolean success = false;
   long startTimeNS = System.nanoTime();
   try {
     for (int i = 0; i < numShards; i++) {
       long timeoutLeftMS =
           Math.max(0, lockTimeoutMS - TimeValue.nsecToMSec((System.nanoTime() - startTimeNS)));
       allLocks.add(shardLock(new ShardId(index, i), timeoutLeftMS));
     }
     success = true;
   } finally {
     if (success == false) {
       logger.trace("unable to lock all shards for index {}", index);
       IOUtils.closeWhileHandlingException(allLocks);
     }
   }
   return allLocks;
 }
예제 #3
0
  public double saveBinaryFileNoBuffer() throws IOException {
    double time = System.nanoTime();
    File file =
        new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithoutBuffer.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    try {
      //            fileOut = new FileOutputStream(file);
      //            outPut = new DataOutputStream(fileOut);
      fileChannel = new RandomAccessFile(file, "rw").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 4096 * 128 * 128);
      counter = edges.size();
      for (Edge e : edges) {
        map.putDouble(e.X1);
        map.putDouble(e.Y1);
        map.putDouble(e.X2);
        map.putDouble(e.Y2);
        map.putDouble(e.color.getRed());
        map.putDouble(e.color.getGreen());
        map.putDouble(e.color.getBlue());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    map.position(0);
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return System.nanoTime() - time;
  }
예제 #4
0
  public double loadBinaryFile() throws IOException {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      double d = map.getDouble();
      currentLevel = (int) d;
      counter = (int) (3 * Math.pow(4, currentLevel - 1));
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      fileChannel.close();
      map.clear();
    }

    return System.nanoTime() - time;
  }