aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Serialization
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-07-11 22:54:22 +0100
committerJustin Clark-Casey (justincc)2012-07-11 22:54:22 +0100
commit916e3bf886ee622e2f18d6eb74f90fee8c630471 (patch)
tree69f9a6d2a7f7041966400f56f46c198f2cc06158 /OpenSim/Framework/Serialization
parentFix build break for windows with missing package for IScriptEngine in prebuil... (diff)
downloadopensim-SC_OLD-916e3bf886ee622e2f18d6eb74f90fee8c630471.zip
opensim-SC_OLD-916e3bf886ee622e2f18d6eb74f90fee8c630471.tar.gz
opensim-SC_OLD-916e3bf886ee622e2f18d6eb74f90fee8c630471.tar.bz2
opensim-SC_OLD-916e3bf886ee622e2f18d6eb74f90fee8c630471.tar.xz
Where possible, use the system Encoding.ASCII and Encoding.UTF8 rather than constructing fresh copies.
The encodings are thread-safe and already used in such a manner in other places. This isn't done where Byte Order Mark output is suppressed, since Encoding.UTF8 is constructed to output the BOM.
Diffstat (limited to 'OpenSim/Framework/Serialization')
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs4
-rw-r--r--OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs4
-rw-r--r--OpenSim/Framework/Serialization/TarArchiveReader.cs8
-rw-r--r--OpenSim/Framework/Serialization/TarArchiveWriter.cs23
4 files changed, 16 insertions, 23 deletions
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
index e8d82d3..a64f01c 100644
--- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
@@ -44,8 +44,6 @@ namespace OpenSim.Framework.Serialization.External
44 { 44 {
45// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
48
49 private static Dictionary<string, Action<LandData, XmlTextReader>> m_ldProcessors 47 private static Dictionary<string, Action<LandData, XmlTextReader>> m_ldProcessors
50 = new Dictionary<string, Action<LandData, XmlTextReader>>(); 48 = new Dictionary<string, Action<LandData, XmlTextReader>>();
51 49
@@ -163,7 +161,7 @@ namespace OpenSim.Framework.Serialization.External
163 /// <exception cref="System.Xml.XmlException"></exception> 161 /// <exception cref="System.Xml.XmlException"></exception>
164 public static LandData Deserialize(byte[] serializedLandData) 162 public static LandData Deserialize(byte[] serializedLandData)
165 { 163 {
166 return Deserialize(m_utf8Encoding.GetString(serializedLandData, 0, serializedLandData.Length)); 164 return Deserialize(Encoding.UTF8.GetString(serializedLandData, 0, serializedLandData.Length));
167 } 165 }
168 166
169 /// <summary> 167 /// <summary>
diff --git a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
index f18435d..19468c3 100644
--- a/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/RegionSettingsSerializer.cs
@@ -40,8 +40,6 @@ namespace OpenSim.Framework.Serialization.External
40 /// </summary> 40 /// </summary>
41 public class RegionSettingsSerializer 41 public class RegionSettingsSerializer
42 { 42 {
43 protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
44
45 /// <summary> 43 /// <summary>
46 /// Deserialize settings 44 /// Deserialize settings
47 /// </summary> 45 /// </summary>
@@ -50,7 +48,7 @@ namespace OpenSim.Framework.Serialization.External
50 /// <exception cref="System.Xml.XmlException"></exception> 48 /// <exception cref="System.Xml.XmlException"></exception>
51 public static RegionSettings Deserialize(byte[] serializedSettings) 49 public static RegionSettings Deserialize(byte[] serializedSettings)
52 { 50 {
53 return Deserialize(m_asciiEncoding.GetString(serializedSettings, 0, serializedSettings.Length)); 51 return Deserialize(Encoding.ASCII.GetString(serializedSettings, 0, serializedSettings.Length));
54 } 52 }
55 53
56 /// <summary> 54 /// <summary>
diff --git a/OpenSim/Framework/Serialization/TarArchiveReader.cs b/OpenSim/Framework/Serialization/TarArchiveReader.cs
index 77c29f8..339a37a 100644
--- a/OpenSim/Framework/Serialization/TarArchiveReader.cs
+++ b/OpenSim/Framework/Serialization/TarArchiveReader.cs
@@ -53,8 +53,6 @@ namespace OpenSim.Framework.Serialization
53 TYPE_CONTIGUOUS_FILE = 8, 53 TYPE_CONTIGUOUS_FILE = 8,
54 } 54 }
55 55
56 protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
57
58 /// <summary> 56 /// <summary>
59 /// Binary reader for the underlying stream 57 /// Binary reader for the underlying stream
60 /// </summary> 58 /// </summary>
@@ -120,13 +118,13 @@ namespace OpenSim.Framework.Serialization
120 if (header[156] == (byte)'L') 118 if (header[156] == (byte)'L')
121 { 119 {
122 int longNameLength = ConvertOctalBytesToDecimal(header, 124, 11); 120 int longNameLength = ConvertOctalBytesToDecimal(header, 124, 11);
123 tarHeader.FilePath = m_asciiEncoding.GetString(ReadData(longNameLength)); 121 tarHeader.FilePath = Encoding.ASCII.GetString(ReadData(longNameLength));
124 //m_log.DebugFormat("[TAR ARCHIVE READER]: Got long file name {0}", tarHeader.FilePath); 122 //m_log.DebugFormat("[TAR ARCHIVE READER]: Got long file name {0}", tarHeader.FilePath);
125 header = m_br.ReadBytes(512); 123 header = m_br.ReadBytes(512);
126 } 124 }
127 else 125 else
128 { 126 {
129 tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); 127 tarHeader.FilePath = Encoding.ASCII.GetString(header, 0, 100);
130 tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); 128 tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray);
131 //m_log.DebugFormat("[TAR ARCHIVE READER]: Got short file name {0}", tarHeader.FilePath); 129 //m_log.DebugFormat("[TAR ARCHIVE READER]: Got short file name {0}", tarHeader.FilePath);
132 } 130 }
@@ -205,7 +203,7 @@ namespace OpenSim.Framework.Serialization
205 { 203 {
206 // Trim leading white space: ancient tars do that instead 204 // Trim leading white space: ancient tars do that instead
207 // of leading 0s :-( don't ask. really. 205 // of leading 0s :-( don't ask. really.
208 string oString = m_asciiEncoding.GetString(bytes, startIndex, count).TrimStart(m_spaceCharArray); 206 string oString = Encoding.ASCII.GetString(bytes, startIndex, count).TrimStart(m_spaceCharArray);
209 207
210 int d = 0; 208 int d = 0;
211 209
diff --git a/OpenSim/Framework/Serialization/TarArchiveWriter.cs b/OpenSim/Framework/Serialization/TarArchiveWriter.cs
index fca909f..122fa8e 100644
--- a/OpenSim/Framework/Serialization/TarArchiveWriter.cs
+++ b/OpenSim/Framework/Serialization/TarArchiveWriter.cs
@@ -41,7 +41,6 @@ namespace OpenSim.Framework.Serialization
41 { 41 {
42// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
44 protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding();
45 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); 44 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
46 45
47 /// <summary> 46 /// <summary>
@@ -85,7 +84,7 @@ namespace OpenSim.Framework.Serialization
85 public void WriteFile(string filePath, byte[] data) 84 public void WriteFile(string filePath, byte[] data)
86 { 85 {
87 if (filePath.Length > 100) 86 if (filePath.Length > 100)
88 WriteEntry("././@LongLink", m_asciiEncoding.GetBytes(filePath), 'L'); 87 WriteEntry("././@LongLink", Encoding.ASCII.GetBytes(filePath), 'L');
89 88
90 char fileType; 89 char fileType;
91 90
@@ -137,7 +136,7 @@ namespace OpenSim.Framework.Serialization
137 oString = "0" + oString; 136 oString = "0" + oString;
138 } 137 }
139 138
140 byte[] oBytes = m_asciiEncoding.GetBytes(oString); 139 byte[] oBytes = Encoding.ASCII.GetBytes(oString);
141 140
142 return oBytes; 141 return oBytes;
143 } 142 }
@@ -156,20 +155,20 @@ namespace OpenSim.Framework.Serialization
156 byte[] header = new byte[512]; 155 byte[] header = new byte[512];
157 156
158 // file path field (100) 157 // file path field (100)
159 byte[] nameBytes = m_asciiEncoding.GetBytes(filePath); 158 byte[] nameBytes = Encoding.ASCII.GetBytes(filePath);
160 int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length; 159 int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length;
161 Array.Copy(nameBytes, header, nameSize); 160 Array.Copy(nameBytes, header, nameSize);
162 161
163 // file mode (8) 162 // file mode (8)
164 byte[] modeBytes = m_asciiEncoding.GetBytes("0000777"); 163 byte[] modeBytes = Encoding.ASCII.GetBytes("0000777");
165 Array.Copy(modeBytes, 0, header, 100, 7); 164 Array.Copy(modeBytes, 0, header, 100, 7);
166 165
167 // owner user id (8) 166 // owner user id (8)
168 byte[] ownerIdBytes = m_asciiEncoding.GetBytes("0000764"); 167 byte[] ownerIdBytes = Encoding.ASCII.GetBytes("0000764");
169 Array.Copy(ownerIdBytes, 0, header, 108, 7); 168 Array.Copy(ownerIdBytes, 0, header, 108, 7);
170 169
171 // group user id (8) 170 // group user id (8)
172 byte[] groupIdBytes = m_asciiEncoding.GetBytes("0000764"); 171 byte[] groupIdBytes = Encoding.ASCII.GetBytes("0000764");
173 Array.Copy(groupIdBytes, 0, header, 116, 7); 172 Array.Copy(groupIdBytes, 0, header, 116, 7);
174 173
175 // file size in bytes (12) 174 // file size in bytes (12)
@@ -181,17 +180,17 @@ namespace OpenSim.Framework.Serialization
181 Array.Copy(fileSizeBytes, 0, header, 124, 11); 180 Array.Copy(fileSizeBytes, 0, header, 124, 11);
182 181
183 // last modification time (12) 182 // last modification time (12)
184 byte[] lastModTimeBytes = m_asciiEncoding.GetBytes("11017037332"); 183 byte[] lastModTimeBytes = Encoding.ASCII.GetBytes("11017037332");
185 Array.Copy(lastModTimeBytes, 0, header, 136, 11); 184 Array.Copy(lastModTimeBytes, 0, header, 136, 11);
186 185
187 // entry type indicator (1) 186 // entry type indicator (1)
188 header[156] = m_asciiEncoding.GetBytes(new char[] { fileType })[0]; 187 header[156] = Encoding.ASCII.GetBytes(new char[] { fileType })[0];
189 188
190 Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 329, 7); 189 Array.Copy(Encoding.ASCII.GetBytes("0000000"), 0, header, 329, 7);
191 Array.Copy(m_asciiEncoding.GetBytes("0000000"), 0, header, 337, 7); 190 Array.Copy(Encoding.ASCII.GetBytes("0000000"), 0, header, 337, 7);
192 191
193 // check sum for header block (8) [calculated last] 192 // check sum for header block (8) [calculated last]
194 Array.Copy(m_asciiEncoding.GetBytes(" "), 0, header, 148, 8); 193 Array.Copy(Encoding.ASCII.GetBytes(" "), 0, header, 148, 8);
195 194
196 int checksum = 0; 195 int checksum = 0;
197 foreach (byte b in header) 196 foreach (byte b in header)