use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ReadOnlyFloatBufferTest method testPutFloatBuffer.
public void testPutFloatBuffer() {
FloatBuffer other = FloatBuffer.allocate(1);
try {
buf.put(other);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put((FloatBuffer) null);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class ReadOnlyLongBufferTest method testPutLongBuffer.
public void testPutLongBuffer() {
LongBuffer other = LongBuffer.allocate(1);
try {
buf.put(other);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put((LongBuffer) null);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
try {
buf.put(buf);
//$NON-NLS-1$
fail("Should throw ReadOnlyBufferException");
} catch (ReadOnlyBufferException e) {
// expected
}
}
use of java.nio.ReadOnlyBufferException in project robovm by robovm.
the class FileChannelTest method test_map_ReadOnly.
/**
* @tests java.nio.channels.FileChannel#map(MapMode,long,long)
*/
public void test_map_ReadOnly() throws IOException {
MappedByteBuffer mapped = null;
// try put something to readonly map
writeDataToFile(fileOfReadOnlyFileChannel);
mapped = readOnlyFileChannel.map(MapMode.READ_ONLY, 0, CONTENT_LENGTH);
try {
mapped.put(TEST_BYTES);
fail("should throw ReadOnlyBufferException.");
} catch (ReadOnlyBufferException ex) {
// expected;
}
assertEquals(CONTENT_LENGTH, mapped.limit());
assertEquals(CONTENT_LENGTH, mapped.capacity());
assertEquals(0, mapped.position());
// try to get a readonly map from read/write channel
writeDataToFile(fileOfReadWriteFileChannel);
mapped = readWriteFileChannel.map(MapMode.READ_ONLY, 0, CONTENT.length());
assertEquals(CONTENT_LENGTH, mapped.limit());
assertEquals(CONTENT_LENGTH, mapped.capacity());
assertEquals(0, mapped.position());
// map not change channel's position
assertEquals(0, readOnlyFileChannel.position());
assertEquals(0, readWriteFileChannel.position());
}
use of java.nio.ReadOnlyBufferException in project XobotOS by xamarin.
the class SSLEngineImpl method unwrap.
/**
* Decodes one complete SSL/TLS record provided in the source buffer.
* If decoded record contained application data, this data will
* be placed in the destination buffers.
* For more information about TLS record fragmentation see
* TLS v 1 specification (http://www.ietf.org/rfc/rfc2246.txt) p 6.2.
* @param src source buffer containing SSL/TLS record.
* @param dsts destination buffers to place received application data.
* @see javax.net.ssl.SSLEngine#unwrap(ByteBuffer,ByteBuffer[],int,int)
* method documentation for more information
*/
@Override
public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException {
if (engine_was_shutteddown) {
return new SSLEngineResult(SSLEngineResult.Status.CLOSED, SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING, 0, 0);
}
if ((src == null) || (dsts == null)) {
throw new IllegalStateException("Some of the input parameters are null");
}
if (!handshake_started) {
beginHandshake();
}
SSLEngineResult.HandshakeStatus handshakeStatus = getHandshakeStatus();
// check if this call was made in spite of handshake status
if ((session == null || engine_was_closed) && (handshakeStatus.equals(SSLEngineResult.HandshakeStatus.NEED_WRAP) || handshakeStatus.equals(SSLEngineResult.HandshakeStatus.NEED_TASK))) {
return new SSLEngineResult(getEngineStatus(), handshakeStatus, 0, 0);
}
if (src.remaining() < recordProtocol.getMinRecordSize()) {
return new SSLEngineResult(SSLEngineResult.Status.BUFFER_UNDERFLOW, getHandshakeStatus(), 0, 0);
}
try {
src.mark();
// check the destination buffers and count their capacity
int capacity = 0;
for (int i = offset; i < offset + length; i++) {
if (dsts[i] == null) {
throw new IllegalStateException("Some of the input parameters are null");
}
if (dsts[i].isReadOnly()) {
throw new ReadOnlyBufferException();
}
capacity += dsts[i].remaining();
}
if (capacity < recordProtocol.getDataSize(src.remaining())) {
return new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW, getHandshakeStatus(), 0, 0);
}
recProtIS.setSourceBuffer(src);
// unwrap the record contained in source buffer, pass it
// to appropriate client protocol (alert, handshake, or app)
// and retrieve the type of unwrapped data
int type = recordProtocol.unwrap();
// process the data and return the result
switch(type) {
case ContentType.HANDSHAKE:
case ContentType.CHANGE_CIPHER_SPEC:
if (handshakeProtocol.getStatus().equals(SSLEngineResult.HandshakeStatus.FINISHED)) {
session = recordProtocol.getSession();
}
break;
case ContentType.APPLICATION_DATA:
break;
case ContentType.ALERT:
if (alertProtocol.isFatalAlert()) {
alertProtocol.setProcessed();
if (session != null) {
session.invalidate();
}
String description = "Fatal alert received " + alertProtocol.getAlertDescription();
shutdown();
throw new SSLException(description);
} else {
if (logger != null) {
logger.println("Warning allert has been received: " + alertProtocol.getAlertDescription());
}
switch(alertProtocol.getDescriptionCode()) {
case AlertProtocol.CLOSE_NOTIFY:
alertProtocol.setProcessed();
close_notify_was_received = true;
if (!close_notify_was_sent) {
closeOutbound();
closeInbound();
} else {
closeInbound();
shutdown();
}
break;
case AlertProtocol.NO_RENEGOTIATION:
alertProtocol.setProcessed();
if (session == null) {
// handshake
throw new AlertException(AlertProtocol.HANDSHAKE_FAILURE, new SSLHandshakeException("Received no_renegotiation " + "during the initial handshake"));
} else {
// just stop the handshake
handshakeProtocol.stop();
}
break;
default:
alertProtocol.setProcessed();
}
}
break;
}
return new SSLEngineResult(getEngineStatus(), getHandshakeStatus(), recProtIS.consumed(), // and get the number of produced bytes:
appData.placeTo(dsts, offset, length));
} catch (BufferUnderflowException e) {
// there was not enought data ource buffer to make complete packet
src.reset();
return new SSLEngineResult(SSLEngineResult.Status.BUFFER_UNDERFLOW, getHandshakeStatus(), 0, 0);
} catch (AlertException e) {
// fatal alert occured
alertProtocol.alert(AlertProtocol.FATAL, e.getDescriptionCode());
engine_was_closed = true;
src.reset();
if (session != null) {
session.invalidate();
}
// to another peer (by wrap method)
throw e.getReason();
} catch (SSLException e) {
throw e;
} catch (IOException e) {
alertProtocol.alert(AlertProtocol.FATAL, AlertProtocol.INTERNAL_ERROR);
engine_was_closed = true;
// to another peer (by wrap method)
throw new SSLException(e.getMessage());
}
}
use of java.nio.ReadOnlyBufferException in project voltdb by VoltDB.
the class SSLBufferDecrypter method tlsunwrap.
public int tlsunwrap(ByteBuffer srcBuffer, ByteBuffer dstBuffer) {
while (true) {
SSLEngineResult result = null;
ByteBuffer slice = dstBuffer.slice();
try {
result = m_sslEngine.unwrap(srcBuffer, slice);
} catch (SSLException | ReadOnlyBufferException | IllegalArgumentException | IllegalStateException e) {
throw new TLSException("ssl engine unwrap fault", e);
}
switch(result.getStatus()) {
case OK:
if (result.bytesProduced() == 0 && !srcBuffer.hasRemaining()) {
return 0;
}
// in m_dstBuffer, newly decrtyped data is between pos and lim
if (result.bytesProduced() > 0) {
dstBuffer.limit(dstBuffer.position() + result.bytesProduced());
return result.bytesProduced();
} else {
continue;
}
case BUFFER_OVERFLOW:
throw new TLSException("SSL engine unexpectedly overflowed when decrypting");
case BUFFER_UNDERFLOW:
throw new TLSException("SSL engine unexpectedly underflowed when decrypting");
case CLOSED:
throw new TLSException("SSL engine is closed on ssl unwrap of buffer.");
}
}
}
Aggregations