1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.common.file;
21
22 import org.waarp.common.command.exception.CommandAbstractException;
23 import org.waarp.common.command.exception.Reply502Exception;
24 import org.waarp.common.command.exception.Reply530Exception;
25 import org.waarp.common.exception.NoRestartException;
26
27 import java.io.IOException;
28
29
30
31
32 public abstract class AbstractFile implements FileInterface {
33
34
35
36 protected boolean isReady;
37
38 @Override
39 public void clear() throws CommandAbstractException {
40 closeFile();
41 isReady = false;
42 }
43
44 @Override
45 public final void checkIdentify() throws Reply530Exception {
46 if (!getSession().getAuth().isIdentified()) {
47 throw new Reply530Exception("User not authentified");
48 }
49 }
50
51 @Override
52 public DataBlock getMarker() throws CommandAbstractException {
53 throw new Reply502Exception("No marker implemented");
54 }
55
56 @Override
57 public boolean restartMarker(final Restart restart)
58 throws CommandAbstractException {
59 try {
60 final long newposition = restart.getPosition();
61 try {
62 setPosition(newposition);
63 } catch (final IOException e) {
64 throw new Reply502Exception("Cannot set the marker position");
65 }
66 return true;
67 } catch (final NoRestartException ignored) {
68
69 }
70 return false;
71 }
72
73 @Override
74 public final boolean retrieve() throws CommandAbstractException {
75 checkIdentify();
76 if (isReady) {
77 restartMarker(getSession().getRestart());
78 return canRead();
79 }
80 return false;
81 }
82
83 @Override
84 public final boolean store() throws CommandAbstractException {
85 checkIdentify();
86 if (isReady) {
87 restartMarker(getSession().getRestart());
88 return canWrite();
89 }
90 return false;
91 }
92
93 }