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