View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package goldengate.ftp.filesystembased;
22  
23  import goldengate.common.command.exception.CommandAbstractException;
24  import goldengate.common.command.exception.Reply502Exception;
25  import goldengate.common.file.filesystembased.FilesystemBasedRestartImpl;
26  import goldengate.ftp.core.command.FtpArgumentCode.TransferMode;
27  import goldengate.ftp.core.command.FtpArgumentCode.TransferStructure;
28  import goldengate.ftp.core.command.FtpArgumentCode.TransferType;
29  import goldengate.ftp.core.data.FtpDataAsyncConn;
30  import goldengate.ftp.core.session.FtpSession;
31  
32  /**
33   * Filesystem implementation of a Restart.<br>
34   * Only FILE+STREAM is supported (byte position in file).
35   *
36   * @author Frederic Bregier
37   *
38   */
39  public class FilesystemBasedFtpRestart extends FilesystemBasedRestartImpl {
40      /**
41       * @param session
42       */
43      public FilesystemBasedFtpRestart(FtpSession session) {
44          super(session);
45      }
46  
47      @Override
48      public boolean restartMarker(String marker) throws CommandAbstractException {
49          FtpDataAsyncConn dataConn = ((FtpSession) getSession()).getDataConn();
50          if (dataConn.getStructure() == TransferStructure.FILE &&
51                  dataConn.getMode() == TransferMode.STREAM &&
52                  dataConn.getType() != TransferType.LENGTH) {
53              long newposition = 0;
54              try {
55                  newposition = Long.parseLong(marker);
56              } catch (NumberFormatException e) {
57                  throw new Reply502Exception(
58                          "Marker must be length in byte as a position");
59              }
60              position = newposition;
61              setSet(true);
62              return true;
63          }
64          throw new Reply502Exception(
65                  "Marker not implemented for such Mode, Type and Structure");
66      }
67  }