aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index ae720f1..ce4af8b 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1510,6 +1510,46 @@ namespace OpenSim.Framework
1510 return result; 1510 return result;
1511 } 1511 }
1512 1512
1513 public static void BinaryToASCII(char[] chars)
1514 {
1515 for (int i = 0; i < chars.Length; i++)
1516 {
1517 char ch = chars[i];
1518 if (ch < 32 || ch > 127)
1519 chars[i] = '.';
1520 }
1521 }
1522
1523 public static string BinaryToASCII(string src)
1524 {
1525 char[] chars = src.ToCharArray();
1526 BinaryToASCII(chars);
1527 return new String(chars);
1528 }
1529
1530 /// <summary>
1531 /// Reads a known number of bytes from a stream.
1532 /// Throws EndOfStreamException if the stream doesn't contain enough data.
1533 /// </summary>
1534 /// <param name="stream">The stream to read data from</param>
1535 /// <param name="data">The array to write bytes into. The array
1536 /// will be completely filled from the stream, so an appropriate
1537 /// size must be given.</param>
1538 public static void ReadStream(Stream stream, byte[] data)
1539 {
1540 int offset = 0;
1541 int remaining = data.Length;
1542
1543 while (remaining > 0)
1544 {
1545 int read = stream.Read(data, offset, remaining);
1546 if (read <= 0)
1547 throw new EndOfStreamException(String.Format("End of stream reached with {0} bytes left to read", remaining));
1548 remaining -= read;
1549 offset += read;
1550 }
1551 }
1552
1513 public static Guid GetHashGuid(string data, string salt) 1553 public static Guid GetHashGuid(string data, string salt)
1514 { 1554 {
1515 byte[] hash = ComputeMD5Hash(data + salt); 1555 byte[] hash = ComputeMD5Hash(data + salt);