1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

[175908] dstore input stream for download

This commit is contained in:
David McKnight 2007-02-28 20:48:10 +00:00
parent 6aa2897748
commit dfe4d13b53
4 changed files with 253 additions and 61 deletions

View file

@ -607,11 +607,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
}
DataElement remoteElement = ds.createObject(universaltemp, de.getType(), remotePath, String.valueOf(mode));
// String tempRoot = getDataStoreRoot();
getDataStoreRoot();
DataElement remoteElement = ds.createObject(universaltemp, de.getType(), remotePath, String.valueOf(mode));
DataElement localElement = ds.createObject(universaltemp, de.getType(), localFile.getAbsolutePath(), encoding);
DataElement bufferSizeElement = ds.createObject(universaltemp, "buffer_size", "" + getBufferDownloadSize(), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -703,57 +699,6 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
}
}
// DownloadListener dlistener = new DownloadListener(shell, monitor, getConnectorService(), status, localFile, remotePath, (long) universalFile.getLength());
// try
// {
// dlistener.waitForUpdate();
// }
// catch (InterruptedException e)
// {
// UniversalSystemPlugin.logError(CLASSNAME + " InterruptedException while waiting for command", e);
// }
// if (!dlistener.isCancelled())
// {
//
// setDataStoreRoot(tempRoot);
//
// ArrayList resultList = remoteElement.getNestedData();
// DataElement resultChild = null;
//
// for (int i = 0; i < resultList.size(); i++)
// {
//
// resultChild = (DataElement) resultList.get(i);
//
// if (resultChild.getType().equals(DOWNLOAD_RESULT_SUCCESS_TYPE))
// {
// return;
// }
// else if (resultChild.getType().equals(DOWNLOAD_RESULT_FILE_NOT_FOUND_EXCEPTION))
// {
// FileNotFoundException e = new FileNotFoundException(resultChild.getName());
// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e);
// throw new RemoteFileIOException(e);
// }
// else if (resultChild.getType().equals(DOWNLOAD_RESULT_UNSUPPORTED_ENCODING_EXCEPTION))
// {
// UnsupportedEncodingException e = new UnsupportedEncodingException(resultChild.getName());
// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e);
// throw new RemoteFileIOException(e);
// }
// else if (resultChild.getType().equals(DOWNLOAD_RESULT_IO_EXCEPTION))
// {
// IOException e = new IOException(resultChild.getName());
// UniversalSystemPlugin.logError(CLASSNAME + "." + "copy: " + "error reading file " + remotePath, e);
// throw new RemoteFileIOException(e);
// }
// }
// }
// else
// {
// throw new RemoteFileCancelledException();
// }
if (monitor != null)
{
//monitor.done();
@ -1334,9 +1279,21 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
/* (non-Javadoc)
* @see org.eclipse.rse.services.files.IFileService#getInputStream(org.eclipse.core.runtime.IProgressMonitor, java.lang.String, java.lang.String, boolean)
*/
public InputStream getInputStream(IProgressMonitor monitor, String remoteParent, String remoteFile, boolean isBinary) throws SystemMessageException {
// TODO Auto-generated method stub
return null;
public InputStream getInputStream(IProgressMonitor monitor, String remoteParent, String remoteFile, boolean isBinary) throws SystemMessageException
{
String remotePath = remoteParent + getSeparator(remoteParent) + remoteFile;
int mode;
if (isBinary)
{
mode = BINARY_MODE;
}
else
{
mode = TEXT_MODE;
}
DStoreInputStream inputStream = new DStoreInputStream(getDataStore(), remotePath, getMinerElement(), getEncoding(monitor), mode);
return inputStream;
}
/* (non-Javadoc)

View file

@ -0,0 +1,203 @@
/********************************************************************************
* Copyright (c) 2007 IBM Corporation. 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.services.dstore.files;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
public class DStoreInputStream extends InputStream
{
private DataStore _dataStore;
private String _remotePath;
private DataElement _minerElement;
private String _encoding;
private int _mode;
private DataElement _cmdStatus;
private File _localFile;
private InputStream _localFileInputStream;
public DStoreInputStream(DataStore dataStore, String remotePath, DataElement minerElement, String encoding, int mode)
{
_dataStore = dataStore;
_remotePath = remotePath;
_minerElement = minerElement;
_encoding = encoding;
_mode = mode;
initDownload();
}
protected void initDownload()
{
DataStore ds = _dataStore;
DataElement universaltemp = _minerElement;
DataElement de = _dataStore.createObject(universaltemp, IUniversalDataStoreConstants.UNIVERSAL_FILE_DESCRIPTOR, _remotePath, _remotePath, "", false); //$NON-NLS-1$
try
{
_localFile = File.createTempFile("download", "rse");
DataElement remoteElement = ds.createObject(universaltemp, de.getType(), _remotePath, String.valueOf(_mode));
DataElement localElement = ds.createObject(universaltemp, de.getType(), _localFile.getAbsolutePath(), _encoding);
DataElement bufferSizeElement = ds.createObject(universaltemp, "buffer_size", "" + IUniversalDataStoreConstants.BUFFER_SIZE, ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
DataElement queryCmd = getCommandDescriptor(de, IUniversalDataStoreConstants.C_DOWNLOAD_FILE);
ArrayList argList = new ArrayList();
argList.add(remoteElement);
argList.add(localElement);
argList.add(bufferSizeElement);
DataElement subject = ds.createObject(universaltemp, de.getType(), _remotePath, String.valueOf(_mode));
_cmdStatus = ds.command(queryCmd, argList, subject);
waitForTempFile();
_localFileInputStream = new FileInputStream(_localFile);
}
catch (Exception e)
{
e.printStackTrace();
}
}
protected DataStore getDataStore()
{
return _dataStore;
}
protected DataElement getCommandDescriptor(DataElement subject, String command)
{
DataElement cmd = _dataStore.localDescriptorQuery(subject.getDescriptor(), command);
return cmd;
}
public void close() throws IOException
{
if (_localFileInputStream != null)
{
_localFileInputStream.close();
}
}
protected void waitForTempFile()
{
if (_localFile != null)
{
while (_localFile.length() == 0)
{
try
{
Thread.sleep(100);
}
catch (Exception e)
{
}
}
}
}
public int read() throws IOException
{
if (_localFileInputStream != null)
{
int result = _localFileInputStream.read();
if (result == -1)
{
System.out.println("result is -1");
}
return result;
}
return 0;
}
public int read(byte[] b, int off, int len) throws IOException
{
if (_localFileInputStream != null)
{
int result = _localFileInputStream.read(b, off, len);
if (result == -1)
{
System.out.println("result is -1");
}
return result;
}
return 0;
}
public int read(byte[] b) throws IOException
{
if (_localFileInputStream != null)
{
int result = _localFileInputStream.read(b);
if (result == -1)
{
System.out.println("result is -1");
}
return result;
}
return 0;
}
public int available() throws IOException
{
if (_localFileInputStream != null)
{
return _localFileInputStream.available();
}
return 0;
}
public synchronized void mark(int readlimit)
{
if (_localFileInputStream != null)
{
_localFileInputStream.mark(readlimit);
}
}
public boolean markSupported()
{
if (_localFileInputStream != null)
{
return _localFileInputStream.markSupported();
}
return false;
}
public synchronized void reset() throws IOException
{
if (_localFileInputStream != null)
{
_localFileInputStream.reset();
}
}
public long skip(long n) throws IOException
{
if (_localFileInputStream != null)
{
return _localFileInputStream.skip(n);
}
return 0;
}
}

View file

@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (c) 2007 IBM Corporation. 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight.
*
* Contributors:
* {Name} (company) - description of contribution.
********************************************************************************/
package org.eclipse.rse.services.dstore.files;
import java.io.IOException;
import java.io.OutputStream;
public class DStoreOutputStream extends OutputStream
{
public DStoreOutputStream()
{
}
public void write(int arg0) throws IOException
{
// TODO Auto-generated method stub
}
}

View file

@ -284,11 +284,11 @@ public class DStoreStatusMonitor implements IDomainListener
// Current thread is UI thread
while (_workingStatuses.contains(status))
{
/*
while (display.readAndDispatch()) {
//Process everything on event queue
}
/*
if ((monitor != null) && (monitor.isCanceled()))
{
setCancelled(status);