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: RemoteTransportImpl.java 111 2008-11-11 11:11:11Z rainf0x $
 
 public class RemoteTransportImpl implements RemoteTransport
 {

   
BUFFER_SIZE. The constant for buffer size.
 
    private static final int BUFFER_SIZE = 20 * 1024;

   
The channel manager.
 
    private final ChannelManager channelManager;

   
The data transmitter.
 
    private final RemoteTransmitter remoteTransmitter;

   
The data receiver.
 
    private final RemoteReceiver remoteReceiver;

   
The temporary folder.
 
    private final File tempDir;

   
Data source url.
 
    private final String sourceUrl;

   
The synchronization latch.
 
    private CountDownLatch latch;

   
RemoteTransportImpl constructor.
 
   
RemoteTransportImpl constructor.

Parameters:
channelManager the channel manager.
tempDir the temporary folder.
sourceUrl data source url.
 
    public RemoteTransportImpl(ChannelManager channelManagerFile tempDirString sourceUrl)
    {
       this. = new CountDownLatch(1);
      this. = channelManager;
      this. = tempDir;
      this. = sourceUrl;
      this. = new RemoteTransmitter(this.);
      this. = new RemoteReceiver(this.);
   }

   
   public void close() throws RemoteWorkspaceInitializationException
   {
   }

   
   public File getWorkspaceData(String repositoryNameString workspaceNameString id)
   {
      RemoteHttpClient client = new RemoteHttpClient();
      String result = client.execute(repositoryNameworkspaceNameid);
      if (result.startsWith("FAIL"))
         throw new RemoteWorkspaceInitializationException("Can not getting the remote workspace data : " + result);
      try
      {
         .await();
      }
      catch (InterruptedException e)
      {
         throw new RemoteWorkspaceInitializationException("The interapted : " + e.getMessage(), e);
      }
      if (.getException() != null)
         throw new RemoteWorkspaceInitializationException("Can not getting the remote workspace data : "
      try
      {
      }
      catch (InvalidChecksumException e)
      {
         new RemoteWorkspaceInitializationException("Can not getting the remote workspace data : " + e.getMessage(), e);
      }
      String filePath = .getContext().getChangesFile().toString();
      return new File(filePath);
   }

   
   public void init() throws RemoteWorkspaceInitializationException
   {
      try
      {
         .connect();
      }
      catch (ReplicationException e)
      {
         throw new RemoteWorkspaceInitializationException("Can not  initialize the transport : " + e.getMessage(), e);
      }
   }

   
   public void sendWorkspaceData(File workspaceDatathrows RemoteWorkspaceInitializationException,
   {
      if (!PrivilegedFileHelper.exists(workspaceData))
         throw new RemoteWorkspaceInitializationException("The file with workspace data not exists.");
      byte[] crc;
      try
      {
         crc = getCheckSum(workspaceData);
         try
         {
            if (.getOtherMembers().size() == 0)
               throw new NoMemberToSendException("No member to sent, member list : "
                  + .getOtherMembers().size());
            .sendChangesLogFile(.getOtherMembers().get(0), workspaceDatacrc);
         }
         catch (IOException e)
         {
            throw new RemoteWorkspaceInitializationException(
               "Can not send the workspace data file : " + e.getMessage(), e);
         }
      }
      catch (NoSuchAlgorithmException e)
      {
         throw new RemoteWorkspaceInitializationException("Can not calculate the checksum for workspace data file : "
            + e.getMessage(), e);
      }
      catch (IOException e)
      {
         throw new RemoteWorkspaceInitializationException("Can not calculate the checksum for workspace data file : "
            + e.getMessage(), e);
      }
   }

   
   {
      try
      {
         InitializationErrorPacket packet =
      }
      catch (IOException e)
      {
         throw new RemoteWorkspaceInitializationException("Cannot send export data " + e.getMessage(), e);
      }
   }

   
getCheckSum.

Parameters:
f the File
Returns:
byte[] the checksum
Throws:
java.security.NoSuchAlgorithmException will be generated the NoSuchAlgorithmException
java.io.IOException will be generated the IOException
   private byte[] getCheckSum(File fthrows NoSuchAlgorithmExceptionIOException
   {
      MessageDigest digest = MessageDigest.getInstance("MD5");
      InputStream in = PrivilegedFileHelper.fileInputStream(f);
      long length = PrivilegedFileHelper.length(f);
      byte[] buff = new byte[];
      for (; length >= length -= )
      {
         in.read(buff);
         digest.update(buff);
      }
      if (length > 0)
      {
         buff = new byte[(int)length];
         in.read(buff);
         digest.update(buff);
      }
      return digest.digest();
   }
New to GrepCode? Check out our FAQ X