• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileRegion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jboss.netty.channel.FileRegion的典型用法代码示例。如果您正苦于以下问题:Java FileRegion类的具体用法?Java FileRegion怎么用?Java FileRegion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileRegion类属于org.jboss.netty.channel包,在下文中一共展示了FileRegion类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: write

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.Channel#write(java.lang.Object)
 */
@Override
public ChannelFuture write(Object message) {
	if(message!=null) {
		if(message instanceof FileRegion) {
			try {
				Pipe pipe = Pipe.open();
				FileRegion fr = (FileRegion)message;
				
				long bytesToRead = fr.getCount();
				fr.transferTo(pipe.sink(), 0L);
				byte[] content = new byte[(int)bytesToRead];
				pipe.source().read(ByteBuffer.wrap(content));
				channelWrites.add(content);
			} catch (Exception ex) {
				log.error("Failed to read content from pipe", ex);
				channelWrites.add(ex);
			}
		} else {
			channelWrites.add(message);
		}
		log.info("Received Channel Write [{}]  type:[{}]", message, message.getClass().getName());
	}
	
	return Channels.succeededFuture(this);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:30,代码来源:InvocationChannel.java


示例2: acquire

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
SendBuffer acquire(Object message) {
    if (message instanceof ChannelBuffer) {
        return acquire((ChannelBuffer) message);
    }
    if (message instanceof FileRegion) {
        return acquire((FileRegion) message);
    }

    throw new IllegalArgumentException(
            "unsupported message type: " + message.getClass());
}
 
开发者ID:urunimi,项目名称:android-netty,代码行数:12,代码来源:SocketSendBufferPool.java


示例3: messageReceived

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
@Override
public void messageReceived( ChannelHandlerContext ctx, MessageEvent e ) throws Exception
{
    HttpRequest request = (HttpRequest)e.getMessage( ) ;
    if( request.getMethod( ) != GET )
    {
        sendError( ctx, FORBIDDEN ) ;
        return ;
    }
    
    final String path = sanitizeUri( request.getUri( ) ) ;
    if( path == null )
    {
        sendError( ctx, FORBIDDEN ) ;
        return ;
    }
    
    File file = new File(path) ;
    if( file.isHidden( ) || !file.exists( ) )
    {
        sendError( ctx, NOT_FOUND ) ;
        return ;
    }
    
    RandomAccessFile raf ;
    try
    {
        raf = new RandomAccessFile( file, "r" ) ;
    }
    catch( FileNotFoundException fnfe )
    {
        sendError( ctx, NOT_FOUND ) ;
        return;
    }
    long fileLength = raf.length( ) ;
    HttpResponse response = new DefaultHttpResponse( HTTP_1_1, OK ) ;
    setContentLength( response, fileLength ) ;
    
    Channel ch = e.getChannel( ) ;
    
    //Escreve a linha inicial do cabe�alho
    ch.write( response ) ;
    
    // Escreve o conte�do
    ChannelFuture writeFuture ;
    if( ch.getPipeline( ).get( SslHandler.class ) != null )
    {
        writeFuture = ch.write( new ChunkedFile( raf, 0, fileLength, 8192 ) ) ;
    }
    else
    {
        final FileRegion region = new DefaultFileRegion( raf.getChannel( ), 0, fileLength ) ;
        writeFuture = ch.write( region ) ;
        writeFuture.addListener( new ChannelFutureProgressListener( )
        {
            @Override
            public void operationComplete( ChannelFuture arg0 ) throws Exception
            {
                region.releaseExternalResources( ) ;
            }
            
            @Override
            public void operationProgressed( ChannelFuture future, long amount, long current,  long total ) throws Exception
            {
                System.out.printf( "%s: %d / %d (+%d)%n", path, current, total, amount );
            }
        }) ;
    }
    
    // Decide se fecha a conex�o ou n�o!!
    if( !isKeepAlive( request ) )
    {
        writeFuture.addListener( ChannelFutureListener.CLOSE ) ;
    }
}
 
开发者ID:wsyssantos,项目名称:BettaServer,代码行数:76,代码来源:BettaUdpFileServerHandler.java


示例4: sendMapOutput

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
protected ChannelFuture sendMapOutput(ChannelHandlerContext ctx, Channel ch,
    String jobId, String mapId, int reduce) throws IOException {
  LocalDirAllocator lDirAlloc = attributes.getLocalDirAllocator();
  FileSystem rfs = ((LocalFileSystem) attributes.getLocalFS()).getRaw();

  ShuffleServerMetrics shuffleMetrics = attributes.getShuffleServerMetrics();
  TaskTracker tracker = attributes.getTaskTracker();

  // Index file
  Path indexFileName = lDirAlloc.getLocalPathToRead(
      TaskTracker.getIntermediateOutputDir(jobId, mapId)
      + "/file.out.index", attributes.getJobConf());
  // Map-output file
  Path mapOutputFileName = lDirAlloc.getLocalPathToRead(
      TaskTracker.getIntermediateOutputDir(jobId, mapId)
      + "/file.out", attributes.getJobConf());

  /**
   * Read the index file to get the information about where
   * the map-output for the given reducer is available.
   */
  IndexRecord info = tracker.getIndexInformation(mapId, reduce,indexFileName);

  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);

  //set the custom "from-map-task" http header to the map task from which
  //the map output data is being transferred
  response.setHeader(MRConstants.FROM_MAP_TASK, mapId);

  //set the custom "Raw-Map-Output-Length" http header to
  //the raw (decompressed) length
  response.setHeader(MRConstants.RAW_MAP_OUTPUT_LENGTH,
      Long.toString(info.rawLength));

  //set the custom "Map-Output-Length" http header to
  //the actual number of bytes being transferred
  response.setHeader(MRConstants.MAP_OUTPUT_LENGTH,
      Long.toString(info.partLength));

  //set the custom "for-reduce-task" http header to the reduce task number
  //for which this map output is being transferred
  response.setHeader(MRConstants.FOR_REDUCE_TASK, Integer.toString(reduce));

  ch.write(response);
  File spillfile = new File(mapOutputFileName.toString());
  RandomAccessFile spill;
  try {
    spill = new RandomAccessFile(spillfile, "r");
  } catch (FileNotFoundException e) {
    LOG.info(spillfile + " not found");
    return null;
  }
  final FileRegion partition = new DefaultFileRegion(
    spill.getChannel(), info.startOffset, info.partLength);
  ChannelFuture writeFuture = ch.write(partition);
  writeFuture.addListener(new ChanneFutureListenerMetrics(partition));
  shuffleMetrics.outputBytes(info.partLength); // optimistic
  LOG.info("Sending out " + info.partLength + " bytes for reduce: " +
           reduce + " from map: " + mapId + " given " +
           info.partLength + "/" + info.rawLength);
  return writeFuture;
}
 
开发者ID:iVCE,项目名称:RDFS,代码行数:63,代码来源:ShuffleHandler.java


示例5: FileSendBuffer

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
FileSendBuffer(FileRegion file) {
    this.file = file;
}
 
开发者ID:urunimi,项目名称:android-netty,代码行数:4,代码来源:SocketSendBufferPool.java


示例6: ChanneFutureListenerMetrics

import org.jboss.netty.channel.FileRegion; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param partition Release resources on this when done
 */
private ChanneFutureListenerMetrics(FileRegion partition) {
  this.partition = partition;
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:9,代码来源:ShuffleHandler.java



注:本文中的org.jboss.netty.channel.FileRegion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KeyAlreadyExistsException类代码示例发布时间:2022-05-22
下一篇:
Java CrashWoodpecker类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap