/** * Force the file to backing storage. Same as calling {@link FileChannel#force(boolean)} with true. */ public void force() { try { fileChannel.force(true); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } }
/** * Rethrow an {@link java.lang.Throwable} preserving the stack trace but making it unchecked. * * @param ex to be rethrown and unchecked. */ public static void rethrowUnchecked(final Throwable ex) { LangUtil.<RuntimeException>rethrow(ex); }
private void forceWrites(final FileChannel channel, final boolean forceWrites, final boolean forceMetadata) { if (null != channel && forceWrites) { try { channel.force(forceMetadata); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } } } }
/** * Rethrow an {@link java.lang.Throwable} preserving the stack trace but making it unchecked. * * @param ex to be rethrown and unchecked. */ public static void rethrowUnchecked(final Throwable ex) { LangUtil.<RuntimeException>rethrow(ex); }
public FlowControl newInstance(final UdpChannel udpChannel, final int streamId, final long registrationId) { FlowControl flowControl = null; try { flowControl = (FlowControl)Class.forName(Configuration.UNICAST_FLOW_CONTROL_STRATEGY) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return flowControl; } }
public FlowControl newInstance(final UdpChannel udpChannel, final int streamId, final long registrationId) { FlowControl flowControl = null; try { flowControl = (FlowControl)Class.forName(Configuration.MULTICAST_FLOW_CONTROL_STRATEGY) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return flowControl; } }
/** * Unmap a {@link MappedByteBuffer} without waiting for the next GC cycle. * * @param buffer to be unmapped. */ public static void unmap(final MappedByteBuffer buffer) { if (null != buffer) { try { UNMAP_BUFFER.invoke(null, buffer); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } } }
/** * Unmap a region of a file. * * @param fileChannel which has been mapped. * @param address at which the mapping begins. * @param length of the mapped region. */ public static void unmap(final FileChannel fileChannel, final long address, final long length) { try { UNMAP_ADDRESS.invoke(fileChannel, address, length); } catch (final IllegalAccessException | InvocationTargetException ex) { LangUtil.rethrowUnchecked(ex); } }
/** * Get the supplier of {@link CongestionControl} implementations which can be used for receivers. * * @return the {@link CongestionControlSupplier} */ static CongestionControlSupplier congestionControlSupplier() { CongestionControlSupplier supplier = null; try { supplier = (CongestionControlSupplier)Class.forName(CONGESTION_CONTROL_STRATEGY_SUPPLIER) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
/** * Close NioSelector down. Returns immediately. */ public void close() { selector.wakeup(); try { selector.close(); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } }
/** * Get the supplier of {@link ReceiveChannelEndpoint}s which can be used for * debugging, monitoring, or modifying the behaviour when receiving from the channel. * * @return the {@link SendChannelEndpointSupplier}. */ static ReceiveChannelEndpointSupplier receiveChannelEndpointSupplier() { ReceiveChannelEndpointSupplier supplier = null; try { supplier = (ReceiveChannelEndpointSupplier)Class.forName(RECEIVE_CHANNEL_ENDPOINT_SUPPLIER) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
/** * Get the supplier of {@link FlowControl}s which can be used for changing behavior of flow control for multicast * publications. * * @return the {@link FlowControlSupplier}. */ static FlowControlSupplier multicastFlowControlSupplier() { FlowControlSupplier supplier = null; try { supplier = (FlowControlSupplier)Class.forName(MULTICAST_FLOW_CONTROL_STRATEGY_SUPPLIER) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
private static Method getFileChannelMethod(final String name, final Class<?>... parameterTypes) { Method method = null; try { method = Class.forName("sun.nio.ch.FileChannelImpl").getDeclaredMethod(name, parameterTypes); method.setAccessible(true); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return method; }
/** * Get the supplier of {@link FlowControl}s which can be used for changing behavior of flow control for unicast * publications. * * @return the {@link FlowControlSupplier}. */ static FlowControlSupplier unicastFlowControlSupplier() { FlowControlSupplier supplier = null; try { supplier = (FlowControlSupplier)Class.forName(UNICAST_FLOW_CONTROL_STRATEGY_SUPPLIER) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
private long getUsableSpace() { long usableSpace = 0; try { usableSpace = fileStore.getUsableSpace(); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return usableSpace; }
/** * Close a {@link java.lang.AutoCloseable} dealing with nulls and exceptions. * This version re-throws exceptions as runtime exceptions. * * @param closeable to be closed. */ public static void close(final AutoCloseable closeable) { try { if (null != closeable) { closeable.close(); } } catch (final Exception e) { LangUtil.rethrowUnchecked(e); } } }
/** * Get the supplier of {@link SendChannelEndpoint}s which can be used for * debugging, monitoring, or modifying the behaviour when sending to the channel. * * @return the {@link SendChannelEndpointSupplier}. */ static SendChannelEndpointSupplier sendChannelEndpointSupplier() { SendChannelEndpointSupplier supplier = null; try { supplier = (SendChannelEndpointSupplier)Class.forName(SEND_CHANNEL_ENDPOINT_SUPPLIER) .getConstructor() .newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
/** * The value {@link #AUTHENTICATOR_SUPPLIER_DEFAULT} or system property * {@link #AUTHENTICATOR_SUPPLIER_PROP_NAME} if set. * * @return {@link #AUTHENTICATOR_SUPPLIER_DEFAULT} or system property * {@link #AUTHENTICATOR_SUPPLIER_PROP_NAME} if set. */ public static AuthenticatorSupplier authenticatorSupplier() { final String supplierClassName = System.getProperty( AUTHENTICATOR_SUPPLIER_PROP_NAME, AUTHENTICATOR_SUPPLIER_DEFAULT); AuthenticatorSupplier supplier = null; try { supplier = (AuthenticatorSupplier)Class.forName(supplierClassName).getConstructor().newInstance(); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } return supplier; }
private void openRecordingSegment() { final String segmentFileName = segmentFileName(recordingId, segmentFileIndex); final File segmentFile = new File(archiveDir, segmentFileName); if (!segmentFile.exists()) { throw new IllegalArgumentException("failed to open recording segment file " + segmentFileName); } try (FileChannel channel = FileChannel.open(segmentFile.toPath(), FILE_OPTIONS, NO_ATTRIBUTES)) { mappedSegmentBuffer = channel.map(READ_ONLY, 0, segmentLength); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } } }
private void write(final ByteBuffer buffer, final FileChannel fileChannel) { try { buffer.clear(); encoder.reset(); final CoderResult coderResult = encoder.encode(CharBuffer.wrap(builder), buffer, false); if (CoderResult.UNDERFLOW != coderResult) { coderResult.throwException(); } buffer.flip(); do { fileChannel.write(buffer); } while (buffer.remaining() > 0); } catch (final Exception ex) { LangUtil.rethrowUnchecked(ex); } } }