Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.ext.initializer.impl;
 
 
 import java.io.File;
Created by The eXo Platform SAS.
Date: 17.03.2009

Author(s):
Alex Reshetnyak
Version:
$Id: RemoteTransmitter.java 111 2008-11-11 11:11:11Z rainf0x $
 
 public class RemoteTransmitter
 {
   
The apache logger.
 
    private static Log log = ExoLogger.getLogger("exo.jcr.component.ext.RemoteTransmitter");

   
The ChannelManager will be send data.
 
    private final ChannelManager channelManager;

   
RemoteTransmitter constructor.

Parameters:
channelManager the ChannelManager.
 
    public RemoteTransmitter(ChannelManager channelManager)
    {
       this. = channelManager;
 
    }

   
sendChangesLogFile.

Parameters:
destinationAddress MemberAddress, the destination address
file File, the data file
checkSum byte[], the checksum for data file
Throws:
java.io.IOException will be generated IOException
 
    protected void sendChangesLogFile(MemberAddress destinationAddressFile filebyte[] checkSumthrows IOException
    {
       if (.isDebugEnabled())
          .debug("Begin send : " + PrivilegedFileHelper.length(file));
 
       InputStream in = PrivilegedFileHelper.fileInputStream(file);
       long totalPacketCount = getPacketCount(PrivilegedFileHelper.length(file), .);
 
       try
       {
          byte[] buff = new byte[.];
          int len;
          long offset = 0;
          AbstractPacket packet;
 
          // Send first packet in all cases. If InputStream is empty too.
          len = in.read(buff);
          if (len < .)
          {
             // cut buffer to original size;
             byte[] b = new byte[len];
             System.arraycopy(buff, 0, b, 0, len);
             buff = b;
         }
         packet =
            new WorkspaceDataPacket(.totalPacketCountcheckSumoffsetbuff);
         .sendPacket(packetdestinationAddress);
         offset += len;
         while ((len = in.read(buff)) > 0)
         {
            if (len < .)
            {
               byte[] b = new byte[len];
               // cut buffer to original size;
               System.arraycopy(buff, 0, b, 0, len);
               buff = b;
            }
            packet =
               new WorkspaceDataPacket(.totalPacketCountcheckSumoffset,
                  buff);
            .sendPacket(packetdestinationAddress);
            offset += len;
         }
      }
      finally
      {
         try
         {
            in.close();
         }
         catch (IOException e)
         {
            .error("Error fo input data stream close. " + ee);
         }
      }
   }

   
getPacketCount.

Parameters:
contentLength long, content length
packetSize long, the packet size
Returns:
long how many packets needs for content
   private long getPacketCount(long contentLengthlong packetSize)
   {
      long count = contentLength / packetSize;
      count += ((count * packetSize - contentLength) != 0) ? 1 : 0;
      return count;
   }
New to GrepCode? Check out our FAQ X