Package java.nio

Examples of java.nio.ByteBuffer.compact()


                        assertEquals(msg + ": Compare byte " + (checked + index), b1, b2);
                    }
                }
                checked += nRead1;
                bFile.compact();
                bIn.compact();
            }
            assertEquals(msg + ": Compared all bytes", size, checked);
            assertEquals(msg + ": InputStream must be at EOF", -1, inChannel.read(bIn));
        }
    }
View Full Code Here


                    long took = System.nanoTime() - next;
                    if (i >= WARMUP)
                        histo.sample(took);
                    else
                        warmup.sample(took);
                    time.compact();
                }

                StringBuilder heading = new StringBuilder("runs\trate\twarmup\tbusy");
                StringBuilder values = new StringBuilder(RUNS + "\t" + RATE + "\t" + WARMUP + "\t" + BUSY);
                for (double perc : new double[]{50, 90, 99, 99.9, 99.99, 99.999}) {
View Full Code Here

        fb.clear();
      }
      while (is.read(fb) != -1 && check.sameSoFar()) {
        fb.flip();
        filters.write(fb);
        fb.compact();
      }
      return check.ultimatelyTheSame();
    } catch (CancelledException ex) {
      repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation");
      return check.ultimatelyTheSame();
View Full Code Here

          buffer.flip();
          // write to the channel, may block
          outChannel.write(buffer);
          // If partial transfer, shift remainder down
          // If buffer is empty, same as doing clear()
          buffer.compact();
        }
        // EOF will leave buffer in fill state
        buffer.flip();
        // make sure the buffer is fully drained.
        while (buffer.hasRemaining()) {
View Full Code Here

            logFacility.dump(getClass(), Warn, "Bad data sink when reading revision %d. Reported %d bytes consumed, byt actually read %d", revisionNumber, consumed, buf.position());
          }
          if (buf.position() == 0) {
            throw new HgInvalidStateException("Bad sink implementation (consumes no bytes) results in endless loop");
          }
          buf.compact(); // ensure (a) there's space for new (b) data starts at 0
          progressSupport.worked(consumed);
        }
        progressSupport.done(); // XXX shall specify whether #done() is invoked always or only if completed successfully.
      } catch (IOException ex) {
        recordFailure(ex);
View Full Code Here

        while (fc.read(buf) != -1) {
          cs.checkCancelled();
          buf.flip();
          int consumed = sink.write(buf);
          progress.worked(flength > Integer.MAX_VALUE ? 1 : consumed);
          buf.compact();
        }
      } catch (IOException ex) {
        throw new HgInvalidFileException("Working copy read failed", ex, f);
      } finally {
        progress.done();
View Full Code Here

            if (i > 0) {
                bytesRead += i;
            }
            tmp.flip();
            dst.put(tmp);
            tmp.compact();
        }
       
        assertEquals(16, bytesRead);
        assertEquals("0123456789abcdef", convert(dst));
        assertTrue(decoder.isCompleted());
View Full Code Here

                    src.flip();
                    if (src.hasRemaining()) {
                        int bytesWritten = encoder.write(src);
                        System.out.println(conn + ": " + bytesWritten + " bytes written");
                    }
                    src.compact();
                   
                    if (src.position() == 0) {
                        if (proxyTask.getClientState() == ProxyTask.REQUEST_BODY_DONE) {
                            encoder.complete();
                        } else {
View Full Code Here

                    src.flip();
                    if (src.hasRemaining()) {
                        int bytesWritten = encoder.write(src);
                        System.out.println(conn + ": " + bytesWritten + " bytes written");
                    }
                    src.compact();

                    if (src.position() == 0) {
                        if (proxyTask.getOriginState() == ProxyTask.RESPONSE_BODY_DONE) {
                            encoder.complete();
                        } else {
View Full Code Here

                } else {
                    ByteBuffer buf = connState.getInbuf();
                    decoder.read(buf);
                    buf.flip();
                    transferred = channel.write(buf);
                    buf.compact();
                }
                connState.incrementInputCount(transferred);
               
                if (decoder.isCompleted()) {
                    // Request entity has been fully received
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.