List of usage examples for io.netty.handler.codec.base64 Base64Encoder Base64Encoder
public Base64Encoder()
From source file:com.github.nettybook.ch7.junit.Base64EncoderTest.java
License:Apache License
@Test public void testEncoder() { String writeData = ""; ByteBuf request = Unpooled.wrappedBuffer(writeData.getBytes()); Base64Encoder encoder = new Base64Encoder(); EmbeddedChannel embeddedChannel = new EmbeddedChannel(encoder); embeddedChannel.writeOutbound(request); ByteBuf response = (ByteBuf) embeddedChannel.readOutbound(); String expect = "7JWI64WV7ZWY7IS47JqU"; assertEquals(expect, response.toString(Charset.defaultCharset())); embeddedChannel.finish();//from www .j a va 2s . c om }
From source file:jgnash.engine.attachment.AttachmentTransferServer.java
License:Open Source License
public boolean startServer(final char[] password) { boolean result = false; // If a password has been specified, create an EncryptionManager if (password != null && password.length > 0) { encryptionManager = new EncryptionManager(password); }/* www . jav a2 s . com*/ try { ServerBootstrap b = new ServerBootstrap(); b.group(eventLoopGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(final SocketChannel ch) throws Exception { ch.pipeline().addLast( new DelimiterBasedFrameDecoder(((TRANSFER_BUFFER_SIZE + 2) / 3) * 4 + PATH_MAX, true, Delimiters.lineDelimiter()), new StringEncoder(CharsetUtil.UTF_8), new StringDecoder(CharsetUtil.UTF_8), new Base64Encoder(), new Base64Decoder(), new ServerTransferHandler()); } }); // Start the server. final ChannelFuture future = b.bind(port).sync(); if (future.isDone() && future.isSuccess()) { result = true; logger.info("File Transfer Server started successfully"); } else { logger.info("Failed to start the File Transfer Server"); } } catch (final InterruptedException e) { logger.log(Level.SEVERE, e.getLocalizedMessage(), e); stopServer(); } return result; }