Пример #1
0
 /// <summary>Wraps a given InputStream with a CryptoInputStream.</summary>
 /// <remarks>
 /// Wraps a given InputStream with a CryptoInputStream. The size of the data
 /// buffer required for the stream is specified by the
 /// "mapreduce.job.encrypted-intermediate-data.buffer.kb" Job configuration
 /// variable.
 /// If the value of 'length' is &gt; -1, The InputStream is additionally
 /// wrapped in a LimitInputStream. CryptoStreams are late buffering in nature.
 /// This means they will always try to read ahead if they can. The
 /// LimitInputStream will ensure that the CryptoStream does not read past the
 /// provided length from the given Input Stream.
 /// </remarks>
 /// <param name="conf"/>
 /// <param name="in"/>
 /// <param name="length"/>
 /// <returns>InputStream</returns>
 /// <exception cref="System.IO.IOException"/>
 public static InputStream WrapIfNecessary(Configuration conf, InputStream @in, long
                                           length)
 {
     if (IsEncryptedSpillEnabled(conf))
     {
         int bufferSize = GetBufferSize(conf);
         if (length > -1)
         {
             @in = new LimitInputStream(@in, length);
         }
         byte[] offsetArray = new byte[8];
         IOUtils.ReadFully(@in, offsetArray, 0, 8);
         long        offset      = ByteBuffer.Wrap(offsetArray).GetLong();
         CryptoCodec cryptoCodec = CryptoCodec.GetInstance(conf);
         byte[]      iv          = new byte[cryptoCodec.GetCipherSuite().GetAlgorithmBlockSize()];
         IOUtils.ReadFully(@in, iv, 0, cryptoCodec.GetCipherSuite().GetAlgorithmBlockSize(
                               ));
         if (Log.IsDebugEnabled())
         {
             Log.Debug("IV read from [" + Base64.EncodeBase64URLSafeString(iv) + "]");
         }
         return(new CryptoInputStream(@in, cryptoCodec, bufferSize, GetEncryptionKey(), iv
                                      , offset + CryptoPadding(conf)));
     }
     else
     {
         return(@in);
     }
 }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        private void OnOpen(ChannelHandlerContext ctx)
        {
            string nnId                  = @params.NamenodeId();
            int    bufferSize            = @params.BufferSize();
            long   offset                = @params.Offset();
            long   length                = @params.Length();
            DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                   .Ok);
            HttpHeaders headers = response.Headers();

            // Allow the UI to access the file
            headers.Set(HttpHeaders.Names.AccessControlAllowMethods, HttpMethod.Get);
            headers.Set(HttpHeaders.Names.AccessControlAllowOrigin, "*");
            headers.Set(HttpHeaders.Names.ContentType, ApplicationOctetStream);
            headers.Set(HttpHeaders.Names.Connection, HttpHeaders.Values.Close);
            DFSClient           dfsclient = NewDfsClient(nnId, conf);
            HdfsDataInputStream @in       = dfsclient.CreateWrappedInputStream(dfsclient.Open(path,
                                                                                              bufferSize, true));

            @in.Seek(offset);
            long contentLength = @in.GetVisibleLength() - offset;

            if (length >= 0)
            {
                contentLength = Math.Min(contentLength, length);
            }
            InputStream data;

            if (contentLength >= 0)
            {
                headers.Set(HttpHeaders.Names.ContentLength, contentLength);
                data = new LimitInputStream(@in, contentLength);
            }
            else
            {
                data = @in;
            }
            ctx.Write(response);
            ctx.WriteAndFlush(new _ChunkedStream_221(dfsclient, data)).AddListener(ChannelFutureListener
                                                                                   .Close);
        }