From d72435693bf950dde2f3f20e9b5d41c91af60456 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 28 May 2010 19:21:00 +0100
Subject: refactor: move GetStream and URI methods from ArchiveReadRequest ->
ArchiveHelpers
---
.../CoreModules/World/Archiver/ArchiveHelpers.cs | 64 ++++++++++++++++++++++
.../World/Archiver/ArchiveReadRequest.cs | 64 +---------------------
2 files changed, 65 insertions(+), 63 deletions(-)
(limited to 'OpenSim/Region/CoreModules/World')
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
index 880bd7c..ddc3dd7 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveHelpers.cs
@@ -25,6 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+using System;
+using System.IO;
+using System.Net;
using OpenMetaverse;
using OpenSim.Framework.Serialization;
using OpenSim.Region.Framework.Scenes;
@@ -60,5 +63,66 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
return ArchiveConstants.CreateOarObjectPath(sog.Name, sog.UUID, sog.AbsolutePosition);
}
+
+ ///
+ /// Resolve path to a working FileStream
+ ///
+ ///
+ ///
+ public static Stream GetStream(string path)
+ {
+ if (File.Exists(path))
+ {
+ return new FileStream(path, FileMode.Open, FileAccess.Read);
+ }
+ else
+ {
+ try
+ {
+ Uri uri = new Uri(path);
+ if (uri.Scheme == "file")
+ {
+ return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read);
+ }
+ else
+ {
+ if (uri.Scheme != "http")
+ throw new Exception(String.Format("Unsupported URI scheme ({0})", path));
+
+ // OK, now we know we have an HTTP URI to work with
+ return URIFetch(uri);
+ }
+ }
+ catch (UriFormatException)
+ {
+ // In many cases the user will put in a plain old filename that cannot be found so assume that
+ // this is the problem rather than confusing the issue with a UriFormatException
+ throw new Exception(String.Format("Cannot find file {0}", path));
+ }
+ }
+ }
+
+ public static Stream URIFetch(Uri uri)
+ {
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
+
+ // request.Credentials = credentials;
+
+ request.ContentLength = 0;
+ request.KeepAlive = false;
+
+ WebResponse response = request.GetResponse();
+ Stream file = response.GetResponseStream();
+
+ // justincc: gonna ignore the content type for now and just try anything
+ //if (response.ContentType != "application/x-oar")
+ // throw new Exception(String.Format("{0} does not identify an OAR file", uri.ToString()));
+
+ if (response.ContentLength == 0)
+ throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
+
+ // return new BufferedStream(file, (int) response.ContentLength);
+ return new BufferedStream(file, 1000000);
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index f97ae5f..bc653ce 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -78,7 +78,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
try
{
- m_loadStream = new GZipStream(GetStream(loadPath), CompressionMode.Decompress);
+ m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress);
}
catch (EntryPointNotFoundException e)
{
@@ -471,68 +471,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver
}
///
- /// Resolve path to a working FileStream
- ///
- ///
- ///
- private Stream GetStream(string path)
- {
- if (File.Exists(path))
- {
- return new FileStream(path, FileMode.Open, FileAccess.Read);
- }
- else
- {
- try
- {
- Uri uri = new Uri(path);
- if (uri.Scheme == "file")
- {
- return new FileStream(uri.AbsolutePath, FileMode.Open, FileAccess.Read);
- }
- else
- {
- if (uri.Scheme != "http")
- throw new Exception(String.Format("Unsupported URI scheme ({0})", path));
-
- // OK, now we know we have an HTTP URI to work with
-
- return URIFetch(uri);
- }
- }
- catch (UriFormatException)
- {
- // In many cases the user will put in a plain old filename that cannot be found so assume that
- // this is the problem rather than confusing the issue with a UriFormatException
- throw new Exception(String.Format("Cannot find file {0}", path));
- }
- }
- }
-
- private static Stream URIFetch(Uri uri)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
-
- // request.Credentials = credentials;
-
- request.ContentLength = 0;
- request.KeepAlive = false;
-
- WebResponse response = request.GetResponse();
- Stream file = response.GetResponseStream();
-
- // justincc: gonna ignore the content type for now and just try anything
- //if (response.ContentType != "application/x-oar")
- // throw new Exception(String.Format("{0} does not identify an OAR file", uri.ToString()));
-
- if (response.ContentLength == 0)
- throw new Exception(String.Format("{0} returned an empty file", uri.ToString()));
-
- // return new BufferedStream(file, (int) response.ContentLength);
- return new BufferedStream(file, 1000000);
- }
-
- ///
/// Load oar control file
///
///
--
cgit v1.1