Esempio n. 1
0
  // returns the entry number or -1 on eof
  int decode(Buffer b) {
    int ptr = 0;
    DecodeAux t = decode_tree;
    int lok = b.look(t.tabn);
    // System.err.println(this+" "+t+" lok="+lok+", tabn="+t.tabn);

    if (lok >= 0) {
      ptr = t.tab[lok];
      b.adv(t.tabl[lok]);
      if (ptr <= 0) {
        return -ptr;
      }
    }
    do {
      switch (b.read1()) {
        case 0:
          ptr = t.ptr0[ptr];
          break;
        case 1:
          ptr = t.ptr1[ptr];
          break;
        case -1:
        default:
          return (-1);
      }
    } while (ptr > 0);
    return (-ptr);
  }
Esempio n. 2
0
    public void run() {

      for (int i = 1; i <= number_of_msgs; i++) {
        try {
          Message msg = new Message(null, buf);
          if (oob) msg.setFlag(Message.Flag.OOB);
          if (dont_bundle) msg.setFlag(Message.Flag.DONT_BUNDLE);
          if (i > 0 && do_print > 0 && i % do_print == 0) System.out.println("-- sent " + i);

          Buffer buffer = writeMessage(msg);

          output_lock.lock(); // need to sync if we have more than 1 sender
          try {
            // msg.writeTo(output);
            output.writeInt(buffer.getLength());
            output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength());
            // output.flush();
          } finally {
            output_lock.unlock();
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
Esempio n. 3
0
 @Test
 public void testGetBuffer() throws Exception {
   Buffer buffer = new FixedBuffer(4);
   buffer.put(1);
   Assert.assertEquals(buffer.getOffset(), 4);
   Assert.assertEquals(buffer.getBuffer().length, 4);
 }
 @Test
 public void bytesNotEmittedToSinkWithoutFlush() throws Exception {
   Buffer sink = new Buffer();
   BufferedSink bufferedSink = new RealBufferedSink(sink);
   bufferedSink.writeUtf8("abc");
   assertEquals(0, sink.size());
 }
Esempio n. 5
0
  private void newImage(Buffer buffer) {
    Object data = buffer.getData();
    if (!(data instanceof int[])) return;
    RGBFormat format = (RGBFormat) buffer.getFormat();

    DirectColorModel dcm =
        new DirectColorModel(
            format.getBitsPerPixel(),
            format.getRedMask(),
            format.getGreenMask(),
            format.getBlueMask());

    sourceImage =
        new MemoryImageSource(
            format.getLineStride(),
            format.getSize().height,
            dcm,
            (int[]) data,
            0,
            format.getLineStride());
    sourceImage.setAnimated(true);
    sourceImage.setFullBufferUpdates(true);
    if (component != null) {
      destImage = component.createImage(sourceImage);
      component.prepareImage(destImage, component);
    }
  }
Esempio n. 6
0
 public boolean isInQuote(Buffer buffer, Position pos) {
   if (buffer.getMode() != this) Debug.bug();
   if (buffer.needsParsing()) buffer.getFormatter().parseBuffer();
   Line line = pos.getLine();
   int offset = pos.getOffset();
   boolean inQuote = false;
   char quoteChar = '\0';
   int state = PHPFormatter.getState(line.flags());
   if (state == STATE_QUOTE) {
     inQuote = true;
     quoteChar = '"';
   } else if (state == STATE_SINGLEQUOTE) {
     inQuote = true;
     quoteChar = '\'';
   }
   for (int i = 0; i < offset; i++) {
     char c = line.charAt(i);
     if (c == '\\') {
       // Escape.
       ++i;
     } else if (inQuote && c == quoteChar) {
       inQuote = false;
     } else if (c == '"' || c == '\'') {
       inQuote = true;
       quoteChar = c;
     }
   }
   return inQuote;
 }
Esempio n. 7
0
 /**
  * Fill the current buffer with bytes from the specified array from the specified offset.
  *
  * @param s source array
  * @param o offset from the beginning of the array
  * @return number of written bytes
  */
 private int write(final byte[] s, final int o) {
   final Buffer bf = bm.current();
   final int len = Math.min(IO.BLOCKSIZE, s.length - o);
   System.arraycopy(s, o, bf.data, 0, len);
   bf.dirty = true;
   return len;
 }
Esempio n. 8
0
    @Override
    public String getToolTipText(int x, int y) {
      if (isMarkerHighlightEnabled()) {
        int lineHeight = textArea.getPainter().getFontMetrics().getHeight();
        if (lineHeight == 0) return null;

        int line = y / lineHeight;
        int start = textArea.getScreenLineStartOffset(line);
        int end = textArea.getScreenLineEndOffset(line);
        if (start == -1 || end == -1) return null;

        Buffer buffer = (Buffer) textArea.getBuffer();
        Marker marker = buffer.getMarkerInRange(start, end);
        if (marker != null) {
          char shortcut = marker.getShortcut();
          if (shortcut == '\0') return jEdit.getProperty("view.gutter.marker.no-name");
          else {
            String[] args = {String.valueOf(shortcut)};
            return jEdit.getProperty("view.gutter.marker", args);
          }
        }
      }

      return null;
    }
Esempio n. 9
0
 /**
  * Return a <code>BufferInfo</code> reflecting the state of a page containing the specified key.
  * The <code>volumeName</code> and <code>treeName</code> parameters specify a {@link Tree} in
  * which to seach for the key. The <code>level</code> parameter indicates whether the data page,
  * or one of the pages on the index path to that data page should be returned. Level 0 refers to
  * the data path, level 1 is the lowest index level, and level d-1 where d is the number of levels
  * in the the tree represents the three's root page.
  *
  * <p>Specify <code>treeName</code> as <code>null</code> to access the volume's directory tree.
  *
  * @param volumeName the name of the volume
  * @param treeName the name of the tree within the volume, or <code>null</code> for the directory
  *     tree
  * @param key a <code>KeyState</code> representing a key
  * @param level tree level: 0 for root, 1...d-1 for index pages of a tree having depth d.
  * @return a <code>BufferInfo</code> object reflecting the selected page, or <code>null</code> if
  *     the specified tree does not exist.
  * @throws RemoteException
  */
 @Override
 public BufferInfo getBufferInfo(
     final String volumeName, final String treeName, final KeyState key, final int level)
     throws RemoteException {
   try {
     Exchange exchange;
     final Volume volume = _persistit.getVolume(volumeName);
     if (volume == null) {
       return null;
     }
     if (treeName == null) {
       exchange = volume.getStructure().directoryExchange();
     } else {
       exchange = _persistit.getExchange(volume, treeName, false);
     }
     key.copyTo(exchange.getKey());
     final Buffer buffer = exchange.fetchBufferCopy(level);
     final BufferInfo info = new BufferInfo();
     buffer.populateInfo(info);
     return info;
   } catch (final TreeNotFoundException tnfe) {
     return null;
   } catch (final PersistitException pe) {
     throw new WrappedRemoteException(pe);
   }
 }
Esempio n. 10
0
  /**
   * Close a buffer.
   *
   * @param buffer The buffer.
   */
  public void closeBuffer(final Buffer buffer) {
    final boolean removed;

    synchronized (m_bufferList) {
      removed = m_bufferList.remove(buffer);
    }

    if (removed) {
      final File file = buffer.getFile();

      if (buffer.equals(getBufferForFile(file))) {
        m_fileBuffers.remove(file);
      }

      if (buffer.equals(getSelectedBuffer())) {
        final Buffer bufferToSelect;

        synchronized (m_bufferList) {
          final int numberOfBuffers = m_bufferList.size();

          bufferToSelect =
              numberOfBuffers > 0 ? (Buffer) m_bufferList.get(numberOfBuffers - 1) : null;
        }

        selectBuffer(bufferToSelect);
      }

      m_listeners.apply(
          new ListenerSupport.Informer<Listener>() {
            public void inform(Listener l) {
              l.bufferRemoved(buffer);
            }
          });
    }
  }
Esempio n. 11
0
 @Override
 public void serialize(Buffer buf) {
   buf.writeString(name);
   buf.writeShort(worldX);
   buf.writeShort(worldY);
   buf.writeString(ownername);
 }
Esempio n. 12
0
  /**
   * Select the buffer for the given file.
   *
   * @param file The file.
   * @return The buffer.
   * @throws ConsoleException If a buffer could not be selected for the file.
   */
  public Buffer selectBufferForFile(File file) throws ConsoleException {
    final Buffer existingBuffer = getBufferForFile(file);
    final Buffer buffer;

    if (existingBuffer != null) {
      buffer = existingBuffer;

      selectBuffer(buffer);

      if (!buffer.isUpToDate()) {
        // The user's edits conflict with a file system change.
        // We ensure the buffer is selected before firing this event because
        // the UI might only raise out of date warnings for selected buffers.
        fireBufferNotUpToDate(buffer);
      }
    } else {
      buffer = new BufferImplementation(m_resources, m_textSourceFactory.create(), file);
      buffer.load();
      addBuffer(buffer);

      m_fileBuffers.put(file, buffer);

      selectBuffer(buffer);
    }

    return buffer;
  }
  /**
   * Replaces text in the specified range with the replacement string.
   *
   * @param view The view
   * @param buffer The buffer
   * @param start The start offset
   * @param end The end offset
   * @return True if the operation was successful, false otherwise
   */
  public static boolean replace(View view, Buffer buffer, int start, int end) {
    if (!buffer.isEditable()) return false;

    // component that will parent any dialog boxes
    Component comp = SearchDialog.getSearchDialog(view);
    if (comp == null) comp = view;

    boolean smartCaseReplace = getSmartCaseReplace();

    try {
      buffer.beginCompoundEdit();

      SearchMatcher matcher = getSearchMatcher();
      if (matcher == null) return false;

      initReplace();

      int retVal = 0;

      retVal += _replace(view, buffer, matcher, start, end, smartCaseReplace);

      if (retVal != 0) return true;
    } catch (Exception e) {
      handleError(comp, e);
    } finally {
      buffer.endCompoundEdit();
    }

    return false;
  } // }}}
Esempio n. 14
0
 @Test
 public void incompleteSegmentsNotEmitted() throws Exception {
   Buffer sink = new Buffer();
   BufferedSink bufferedSink = new RealBufferedSink(sink);
   bufferedSink.writeUtf8(repeat('a', Segment.SIZE * 3 - 1));
   assertEquals(Segment.SIZE * 2, sink.size());
 }
Esempio n. 15
0
  private boolean step() {
    if (next != NONE) return true;

    while (next == NONE) {
      if (buffer.isEmpty()) {
        if (completed) {
          return false;
        } else if (sourceIter.hasNext()) {
          Object iter = null;
          if (multi) iter = xf.applyTo(RT.cons(null, sourceIter.next()));
          else iter = xf.invoke(null, sourceIter.next());

          if (RT.isReduced(iter)) {
            xf.invoke(null);
            completed = true;
          }
        } else {
          xf.invoke(null);
          completed = true;
        }
      } else {
        next = buffer.remove();
      }
    }
    return true;
  }
Esempio n. 16
0
  private PropertyRecord getRecordFromBuffer(long id, Buffer buffer) {
    int offsetAtBeggining = buffer.getOffset();
    PropertyRecord record = new PropertyRecord(id);

    /*
     * [pppp,nnnn] previous, next high bits
     */
    byte modifiers = buffer.get();
    long prevMod = ((modifiers & 0xF0L) << 28);
    long nextMod = ((modifiers & 0x0FL) << 32);
    long prevProp = buffer.getUnsignedInt();
    long nextProp = buffer.getUnsignedInt();
    record.setPrevProp(longFromIntAndMod(prevProp, prevMod));
    record.setNextProp(longFromIntAndMod(nextProp, nextMod));

    while (buffer.getOffset() - offsetAtBeggining < RECORD_SIZE) {
      PropertyBlock newBlock = getPropertyBlock(buffer);
      if (newBlock != null) {
        record.addPropertyBlock(newBlock);
        record.setInUse(true);
      } else {
        // We assume that storage is defragged
        break;
      }
    }
    return record;
  }
Esempio n. 17
0
  /** ********************* CONSTRUCTOR **************************** */
  public RyanairInspector2GUI() {

    bufferNavegadores = new Buffer(new CircularQueue(SIZE));
    for (Navegador n : navegadores) {
      bufferNavegadores.Put(n);
    }

    bufferVuelos = new Buffer(new CircularQueue(SIZE));
    System.out.println(rutaActual);
    System.out.println("-- Empieza lectura fichero --");
    vuelos = UtilsIO.leerFicheroDatosConsultaVuelos(rutaActual + nomFichConsultas);
    for (Vuelo v : vuelos) {
      bufferVuelos.Put(v);
      System.out.println(v.toString());
    }
    System.out.println("-- Termina lectura fichero --");

    /*__ CREAMOS UNA INSTANCIA PARA CAPTURAR UN VUELO */
    unvueloRyanair = new RyanairInspector2();

    creaContenidos();

    // Iniciamos la carga de la pagina
    iniciaCaptura(table);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
    // System.out.println("despues de dispose");

  }
Esempio n. 18
0
 private static void _testMessage(Message msg) throws Exception {
   Buffer buf = Util.messageToByteBuffer(msg);
   Message msg2 = Util.byteBufferToMessage(buf.getBuf(), buf.getOffset(), buf.getLength());
   Assert.assertEquals(msg.getSrc(), msg2.getSrc());
   Assert.assertEquals(msg.getDest(), msg2.getDest());
   Assert.assertEquals(msg.getLength(), msg2.getLength());
 }
Esempio n. 19
0
  /**
   * @param cancel {@code True} to close with cancellation.
   * @throws GridException If failed.
   */
  @Override
  public void close(boolean cancel) throws GridException {
    if (!closed.compareAndSet(false, true)) return;

    busyLock.block();

    if (log.isDebugEnabled())
      log.debug("Closing data loader [ldr=" + this + ", cancel=" + cancel + ']');

    GridException e = null;

    try {
      // Assuming that no methods are called on this loader after this method is called.
      if (cancel) {
        cancelled = true;

        for (Buffer buf : bufMappings.values()) buf.cancelAll();
      } else doFlush();

      ctx.event().removeLocalEventListener(discoLsnr);

      ctx.io().removeMessageListener(topic);
    } catch (GridException e0) {
      e = e0;
    }

    fut.onDone(null, e);

    if (e != null) throw e;
  }
  @Test
  public void testErase() {
    engine.erase();
    Assert.assertTrue("Erase() - Buffer isn't empty", buffer.getText().equals(""));
    Assert.assertTrue(
        "Erase() - Selection isn't (0, 0)",
        selection.getStart() == 0 && selection.getLength() == 0);

    buffer.setText("test");
    engine.erase();
    Assert.assertTrue(
        "Erase() - Buffer content isn't the set text", buffer.getText().equals("test"));
    Assert.assertTrue(
        "Erase() - Selection isn't (0, 0)",
        selection.getStart() == 0 && selection.getLength() == 0);

    selection.setStart(4);
    engine.erase();
    Assert.assertTrue(
        "Erase() - Buffer content isn't the set text", buffer.getText().equals("tes"));
    Assert.assertTrue(
        "Erase() - Selection isn't (3, 0)",
        selection.getStart() == 3 && selection.getLength() == 0);

    selection.setStart(0);
    selection.setLength(3);
    engine.erase();
    Assert.assertTrue("Erase() - Buffer content isn't the set text", buffer.getText().equals(""));
    Assert.assertTrue(
        "Erase() - Selection isn't (0, 0)",
        selection.getStart() == 0 && selection.getLength() == 0);
  }
  @Test
  public void testCopy() {
    engine.copy();
    Assert.assertTrue("Copy() - Buffer isn't empty", buffer.getText().equals(""));
    Assert.assertTrue("Copy() - Clipboard isn't empty", clipboard.getText().equals(""));
    Assert.assertTrue(
        "Copy() - Selection isn't (0, 0)", selection.getStart() == 0 && selection.getLength() == 0);

    buffer.setText("test");
    engine.copy();
    Assert.assertTrue(
        "Copy() - Buffer content isn't the set text", buffer.getText().equals("test"));
    Assert.assertTrue("Copy() - Clipboard isn't empty", clipboard.getText().equals(""));
    Assert.assertTrue(
        "Copy() - Selection isn't (0, 0)", selection.getStart() == 0 && selection.getLength() == 0);

    selection.setStart(0);
    selection.setLength(4);
    engine.copy();
    Assert.assertTrue(
        "Copy() - Buffer content isn't the set text", buffer.getText().equals("test"));
    Assert.assertTrue("Copy() - Clipboard is empty", clipboard.getText().equals("test"));
    Assert.assertTrue(
        "Copy() - Selection isn't (0, 4)", selection.getStart() == 0 && selection.getLength() == 4);

    selection.setLength(0);
    engine.copy();
    Assert.assertTrue(
        "Copy() - Buffer content isn't the set text", buffer.getText().equals("test"));
    Assert.assertTrue(
        "Copy() - Clipboard is changed but copy when no text selected",
        clipboard.getText().equals("test"));
    Assert.assertTrue(
        "Copy() - Selection isn't (0, 0)", selection.getStart() == 0 && selection.getLength() == 0);
  }
Esempio n. 22
0
  public boolean equalsIgnoreCase(Buffer b) {
    if (b == this) {
      return true;
    }

    if (b.length() != length()) {
      return false;
    }
    if ((this._hash != 0) && (b instanceof AbstractBuffer)) {
      AbstractBuffer ab = (AbstractBuffer) b;
      if ((ab._hash != 0) && (this._hash != ab._hash)) {
        return false;
      }
    }

    int get = getIndex();
    int bi = b.putIndex();

    byte[] array = array();
    byte[] barray = b.array();
    int i;
    if ((array != null) && (barray != null)) {
      for (i = putIndex(); i-- > get; ) {
        byte b1 = array[i];
        bi--;
        byte b2 = barray[bi];
        if (b1 != b2) {
          if ((97 <= b1) && (b1 <= 122)) {
            b1 = (byte) (b1 - 97 + 65);
          }
          if ((97 <= b2) && (b2 <= 122)) {
            b2 = (byte) (b2 - 97 + 65);
          }
          if (b1 != b2) {
            return false;
          }
        }
      }
    } else {
      for (i = putIndex(); i-- > get; ) {
        byte b1 = peek(i);
        bi--;
        byte b2 = b.peek(bi);
        if (b1 != b2) {
          if ((97 <= b1) && (b1 <= 122)) {
            b1 = (byte) (b1 - 97 + 65);
          }

          if ((97 <= b2) && (b2 <= 122)) {
            b2 = (byte) (b2 - 97 + 65);
          }

          if (b1 != b2) {
            return false;
          }
        }
      }
    }
    return true;
  }
Esempio n. 23
0
 public Buffer getOffsettedBuffer(int id) {
   if ((id & 0xFFFFFFFFL) != buffer.position()) {
     throw new InvalidRecordException(
         "Id[" + id + "] not equal to buffer position[" + buffer.position() + "]");
   }
   return buffer;
 }
Esempio n. 24
0
 /**
  * insert text.
  *
  * <p>/** invokes an Action.
  *
  * @param view The view to run the script in.
  * @param node The node item
  * @param text The node content to be inserted.
  */
 public static void insertText(View view, String text, XTreeNode node) {
   CommandQueue queue = new CommandQueue();
   ScriptContext context = new ScriptContext(view, node, queue);
   Buffer buffer = view.getBuffer();
   buffer.beginCompoundEdit();
   InsertTextCommand.insertText(text, context);
   buffer.endCompoundEdit();
 }
Esempio n. 25
0
 @Test
 public void readFully() throws Exception {
   sink.writeUtf8(repeat('a', 10000));
   Buffer sink = new Buffer();
   source.readFully(sink, 9999);
   assertEquals(repeat('a', 9999), sink.readUtf8());
   assertEquals("a", source.readUtf8());
 }
Esempio n. 26
0
 @Test
 public void bufferedSinkEmitMultipleSegments() throws IOException {
   Buffer sink = new Buffer();
   BufferedSink bufferedSink = new RealBufferedSink(sink);
   bufferedSink.writeUtf8(repeat('a', Segment.SIZE * 4 - 1));
   assertEquals(Segment.SIZE * 3, sink.size());
   assertEquals(Segment.SIZE - 1, bufferedSink.buffer().size());
 }
Esempio n. 27
0
 @Override
 public void write1(final int pre, final int off, final int v) {
   final int o = off + cursor(pre);
   final Buffer bf = bm.current();
   final byte[] b = bf.data;
   b[o] = (byte) v;
   bf.dirty = true;
 }
Esempio n. 28
0
  @Test
  public void testRead4PrefixedString_Null() throws Exception {
    byte[] length = Ints.toByteArray(-1);

    Buffer buffer = new FixedBuffer(length);
    String prefixedString = buffer.read4PrefixedString();
    Assert.assertEquals(prefixedString, null);
  }
Esempio n. 29
0
 private void newBuffer() {
   this.buffer = allocator.allocate(PageFormat.PAGE_HEADER_SIZE + fixedRecordSize);
   this.bufferSlice = Slices.wrappedBuffer(buffer.array(), buffer.offset(), buffer.capacity());
   this.count = 0;
   this.position = PageFormat.PAGE_HEADER_SIZE;
   this.stringReferences.clear();
   this.stringReferenceSize = 0;
 }
Esempio n. 30
0
 @Test
 public void readExhaustedSource() throws Exception {
   Buffer sink = new Buffer();
   sink.writeUtf8(repeat('a', 10));
   assertEquals(-1, source.read(sink, 10));
   assertEquals(10, sink.size());
   assertTrue(source.exhausted());
 }