184ef3f95a4e6d1c5156223f948f26492041f8cc
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / operations / RemoteFile.java
1 package com.owncloud.android.oc_framework.operations;
2
3 import java.io.Serializable;
4
5 import android.os.Parcel;
6 import android.os.Parcelable;
7
8 import com.owncloud.android.oc_framework.utils.FileUtils;
9
10
11 public class RemoteFile implements Parcelable, Serializable{
12
13 /** Generated - should be refreshed every time the class changes!! */
14 private static final long serialVersionUID = 7256606476031992757L;
15
16 private String mRemotePath;
17 private String mMimeType;
18 private long mLength;
19 private long mCreationTimestamp;
20 private long mModifiedTimestamp;
21 private String mEtag;
22
23 /**
24 * Getters and Setters
25 */
26
27 public String getRemotePath() {
28 return mRemotePath;
29 }
30
31 public void setRemotePath(String remotePath) {
32 this.mRemotePath = remotePath;
33 }
34
35 public String getMimeType() {
36 return mMimeType;
37 }
38
39 public void setMimeType(String mimeType) {
40 this.mMimeType = mimeType;
41 }
42
43 public long getLength() {
44 return mLength;
45 }
46
47 public void setLength(long length) {
48 this.mLength = length;
49 }
50
51 public long getCreationTimestamp() {
52 return mCreationTimestamp;
53 }
54
55 public void setCreationTimestamp(long creationTimestamp) {
56 this.mCreationTimestamp = creationTimestamp;
57 }
58
59 public long getModifiedTimestamp() {
60 return mModifiedTimestamp;
61 }
62
63 public void setModifiedTimestamp(long modifiedTimestamp) {
64 this.mModifiedTimestamp = modifiedTimestamp;
65 }
66
67 public String getEtag() {
68 return mEtag;
69 }
70
71 public void setEtag(String etag) {
72 this.mEtag = etag;
73 }
74
75 /**
76 * Create new {@link RemoteFile} with given path.
77 *
78 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
79 *
80 * @param path The remote path of the file.
81 */
82 public RemoteFile(String path) {
83 resetData();
84 if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
85 throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
86 }
87 mRemotePath = path;
88 }
89
90 /**
91 * Used internally. Reset all file properties
92 */
93 private void resetData() {
94 mRemotePath = null;
95 mMimeType = null;
96 mLength = 0;
97 mCreationTimestamp = 0;
98 mModifiedTimestamp = 0;
99 mEtag = null;
100 }
101
102 /**
103 * Parcelable Methods
104 */
105 public static final Parcelable.Creator<RemoteFile> CREATOR = new Parcelable.Creator<RemoteFile>() {
106 @Override
107 public RemoteFile createFromParcel(Parcel source) {
108 return new RemoteFile(source);
109 }
110
111 @Override
112 public RemoteFile[] newArray(int size) {
113 return new RemoteFile[size];
114 }
115 };
116
117
118 /**
119 * Reconstruct from parcel
120 *
121 * @param source The source parcel
122 */
123 private RemoteFile(Parcel source) {
124 mRemotePath = source.readString();
125 mMimeType = source.readString();
126 mLength = source.readLong();
127 mCreationTimestamp = source.readLong();
128 mModifiedTimestamp = source.readLong();
129 mEtag = source.readString();
130 }
131
132 @Override
133 public int describeContents() {
134 return this.hashCode();
135 }
136
137 @Override
138 public void writeToParcel(Parcel dest, int flags) {
139 dest.writeString(mRemotePath);
140 dest.writeString(mMimeType);
141 dest.writeLong(mLength);
142 dest.writeLong(mCreationTimestamp);
143 dest.writeLong(mModifiedTimestamp);
144 dest.writeString(mEtag);
145 }
146
147
148 }