Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f102804123e87f3dde66988fbc35423d44b46edf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/****************************************************************************
 * Copyright (c) 2004 Composent, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Composent, Inc. - initial API and implementation
 *****************************************************************************/

package org.eclipse.ecf.internal.provider.filetransfer.efs;

import java.io.*;
import java.net.URI;
import java.util.Map;
import org.eclipse.core.filesystem.*;
import org.eclipse.ecf.core.util.Proxy;
import org.eclipse.ecf.filetransfer.*;
import org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent;
import org.eclipse.ecf.filetransfer.identity.IFileID;
import org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer;
import org.eclipse.ecf.provider.filetransfer.util.JREProxyHelper;

/**
 * 
 */
public class RetrieveFileTransfer extends AbstractRetrieveFileTransfer {

	JREProxyHelper proxyHelper = null;
	String fileName;

	public RetrieveFileTransfer() {
		super();
		proxyHelper = new JREProxyHelper();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #hardClose()
	 */
	public String getRemoteFileName() {
		return fileName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #hardClose()
	 */
	protected void hardClose() {
		super.hardClose();
		if (proxyHelper != null) {
			proxyHelper.dispose();
			proxyHelper = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #openStreams()
	 */
	protected void openStreams() throws IncomingFileTransferException {
		try {
			final IFileStore fileStore = EFS.getStore(new URI(
					getRemoteFileURL().getPath()));
			final IFileInfo info = fileStore.fetchInfo();
			setFileLength(info.getLength());
			setInputStream(fileStore.openInputStream(0, null));
			setLastModifiedTime(info.getLastModified());
			fileName = info.getName();
			listener.handleTransferEvent(new IIncomingFileTransferReceiveStartEvent() {
				public IIncomingFileTransfer getSource() {
					return RetrieveFileTransfer.this;
				}

				public IFileID getFileID() {
					return remoteFileID;
				}

				public IIncomingFileTransfer receive(File localFileToSave)
						throws IOException {
					return receive(localFileToSave, null);
				}

				public IIncomingFileTransfer receive(File localFileToSave,
						FileTransferJob fileTransferJob) throws IOException {
					setOutputStream(new BufferedOutputStream(
							new FileOutputStream(localFileToSave)));
					setupAndScheduleJob(fileTransferJob);
					return RetrieveFileTransfer.this;
				}

				public String toString() {
					final StringBuffer sb = new StringBuffer(
							"IIncomingFileTransferReceiveStartEvent["); //$NON-NLS-1$
					sb.append("isdone=").append(done).append(";"); //$NON-NLS-1$ //$NON-NLS-2$
					sb.append("bytesReceived=").append( //$NON-NLS-1$
							bytesReceived).append("]"); //$NON-NLS-1$
					return sb.toString();
				}

				public void cancel() {
					hardClose();
				}

				/**
				 * @param streamToStore
				 * @return incoming file transfer instance.
				 * @throws IOException
				 *             not thrown in this implementation.
				 */
				public IIncomingFileTransfer receive(OutputStream streamToStore)
						throws IOException {
					return receive(streamToStore, null);
				}

				/**
				 * @throws IOException
				 *             not actually thrown by this implementation.
				 */
				public IIncomingFileTransfer receive(
						OutputStream streamToStore,
						FileTransferJob fileTransferJob) throws IOException {
					setOutputStream(streamToStore);
					setCloseOutputStream(false);
					setupAndScheduleJob(fileTransferJob);
					return RetrieveFileTransfer.this;
				}

				public Map getResponseHeaders() {
					return null;
				}

			});

		} catch (final Exception e) {
			throw new IncomingFileTransferException(e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #doPause()
	 */
	protected boolean doPause() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #doResume()
	 */
	protected boolean doResume() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
	 * #setupProxy(org.eclipse.ecf.core.util.Proxy)
	 */
	protected void setupProxy(Proxy proxy) {
		proxyHelper.setupProxy(proxy);
	}
}

Back to the top