67 throw new NullPointerException("\"" + name + "\" is null!");
68 }
69
70 /**
71 * Write all remaining bytes in buffer to the given channel.
72 * If the channel is selectable then it must be configured blocking.
73 */
74 private static void writeFullyImpl(WritableByteChannel ch, ByteBuffer bb)
75 throws IOException
76 {
77 while (bb.remaining() > 0) {
78 int n = ch.write(bb);
79 if (n <= 0)
80 throw new RuntimeException("no bytes written");
81 }
82 }
83
84 /**
85 * Write all remaining bytes in buffer to the given channel.
86 *
87 * @throws IllegalBlockingException
88 * If the channel is selectable and configured non-blocking.
89 */
90 private static void writeFully(WritableByteChannel ch, ByteBuffer bb)
91 throws IOException
92 {
93 if (ch instanceof SelectableChannel) {
94 SelectableChannel sc = (SelectableChannel)ch;
95 synchronized (sc.blockingLock()) {
96 if (!sc.isBlocking())
97 throw new IllegalBlockingModeException();
98 writeFullyImpl(ch, bb);
99 }
100 } else {
101 writeFullyImpl(ch, bb);
102 }
103 }
104
105 // -- Byte streams from channels --
106
107 /**
|
67 throw new NullPointerException("\"" + name + "\" is null!");
68 }
69
70 /**
71 * Write all remaining bytes in buffer to the given channel.
72 * If the channel is selectable then it must be configured blocking.
73 */
74 private static void writeFullyImpl(WritableByteChannel ch, ByteBuffer bb)
75 throws IOException
76 {
77 while (bb.remaining() > 0) {
78 int n = ch.write(bb);
79 if (n <= 0)
80 throw new RuntimeException("no bytes written");
81 }
82 }
83
84 /**
85 * Write all remaining bytes in buffer to the given channel.
86 *
87 * @throws IllegalBlockingModeException
88 * If the channel is selectable and configured non-blocking.
89 */
90 private static void writeFully(WritableByteChannel ch, ByteBuffer bb)
91 throws IOException
92 {
93 if (ch instanceof SelectableChannel) {
94 SelectableChannel sc = (SelectableChannel)ch;
95 synchronized (sc.blockingLock()) {
96 if (!sc.isBlocking())
97 throw new IllegalBlockingModeException();
98 writeFullyImpl(ch, bb);
99 }
100 } else {
101 writeFullyImpl(ch, bb);
102 }
103 }
104
105 // -- Byte streams from channels --
106
107 /**
|