public static void main(String[] args) throws IOException {
   Path pIn = FileSystems.getDefault().getPath(args[0]);
   Path pOut = FileSystems.getDefault().getPath(args[1]);
   ByteChannel in = Files.newByteChannel(pIn, StandardOpenOption.READ);
   ByteChannel out =
       Files.newByteChannel(pOut, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
   ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
   int nb = 0;
   while ((nb = in.read(bb)) != -1) {
     bb.flip();
     while (bb.hasRemaining()) {
       byte b = bb.get();
       ByteBuffer w;
       if (b == CONST) {
         byte[] arr = {b, b};
         w = ByteBuffer.wrap(arr);
       } else {
         byte[] arr = {b};
         w = ByteBuffer.wrap(arr);
       }
       out.write(w);
     }
     bb.clear();
   }
   in.close();
   out.close();
 }
예제 #2
0
 public void close(ThreadContext tc) {
   try {
     chan.close();
   } catch (IOException e) {
     throw ExceptionHandling.dieInternal(tc, e);
   }
 }
예제 #3
0
  /**
   * @param remote Indicates who "generated" <code>code</code>.<br>
   *     <code>true</code> means that this endpoint received the <code>code</code> from the other
   *     endpoint.<br>
   *     false means this endpoint decided to send the given code,<br>
   *     <code>remote</code> may also be true if this endpoint started the closing handshake since
   *     the other endpoint may not simply echo the <code>code</code> but close the connection the
   *     same time this endpoint does do but with an other <code>code</code>. <br>
   */
  protected synchronized void closeConnection(int code, String message, boolean remote) {
    if (readystate == READYSTATE.CLOSED) {
      return;
    }

    if (key != null) {
      // key.attach( null ); //see issue #114
      key.cancel();
    }
    if (channel != null) {
      try {
        channel.close();
      } catch (IOException e) {
        wsl.onWebsocketError(this, e);
      }
    }
    try {
      this.wsl.onWebsocketClose(this, code, message, remote);
    } catch (RuntimeException e) {
      wsl.onWebsocketError(this, e);
    }
    if (draft != null) draft.reset();
    handshakerequest = null;

    readystate = READYSTATE.CLOSED;
    this.outQueue.clear();
  }
예제 #4
0
 private void close(ByteChannel channel) {
   pendingChannels.remove(channel);
   try {
     channel.close();
   } catch (IOException e) {
     // Best effort
   }
 }
예제 #5
0
 public void stop() {
   try {
     channel.close();
     logger.debug("~~ [CLOSE]");
   } catch (IOException e) {
     throw new ClientException("Unable to close socket connection properly." + e.getMessage(), e);
   }
 }
예제 #6
0
 @Override
 public void close() throws IOException {
   socket.close();
 }