diff options
author | Jeff Ames | 2008-06-04 09:59:27 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-04 09:59:27 +0000 |
commit | 4ec4e16c809cf86a63b736d2b7b6ad7291595a5f (patch) | |
tree | cfa896ef9057228171e2ee39c4807060101ba90b /OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs | |
parent | * If a ThreadAbortException reaches AuthUser() then let it pass through unmol... (diff) | |
download | opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.zip opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.gz opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.bz2 opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.xz |
Formatting cleanup, minor refactoring, svn properties.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs index b199d5f..463e172 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs | |||
@@ -39,24 +39,24 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
39 | public class TarArchiveReader | 39 | public class TarArchiveReader |
40 | { | 40 | { |
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 42 | ||
43 | protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); | 43 | protected static ASCIIEncoding m_asciiEncoding = new ASCIIEncoding(); |
44 | 44 | ||
45 | /// <summary> | 45 | /// <summary> |
46 | /// Binary reader for the underlying stream | 46 | /// Binary reader for the underlying stream |
47 | /// </summary> | 47 | /// </summary> |
48 | protected BinaryReader m_br; | 48 | protected BinaryReader m_br; |
49 | 49 | ||
50 | /// <summary> | 50 | /// <summary> |
51 | /// Used to trim off null chars | 51 | /// Used to trim off null chars |
52 | /// </summary> | 52 | /// </summary> |
53 | protected char[] m_nullCharArray = new char[] { '\0' }; | 53 | protected char[] m_nullCharArray = new char[] { '\0' }; |
54 | 54 | ||
55 | public TarArchiveReader(string archivePath) | 55 | public TarArchiveReader(string archivePath) |
56 | { | 56 | { |
57 | m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open)); | 57 | m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open)); |
58 | } | 58 | } |
59 | 59 | ||
60 | /// <summary> | 60 | /// <summary> |
61 | /// Are we at the end of the archive? | 61 | /// Are we at the end of the archive? |
62 | /// </summary> | 62 | /// </summary> |
@@ -64,13 +64,13 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
64 | public bool AtEof() | 64 | public bool AtEof() |
65 | { | 65 | { |
66 | // If we've reached the end of the archive we'll be in null block territory, which means | 66 | // If we've reached the end of the archive we'll be in null block territory, which means |
67 | // the next byte will be 0 | 67 | // the next byte will be 0 |
68 | if (m_br.PeekChar() == 0) | 68 | if (m_br.PeekChar() == 0) |
69 | return true; | 69 | return true; |
70 | 70 | ||
71 | return false; | 71 | return false; |
72 | } | 72 | } |
73 | 73 | ||
74 | /// <summary> | 74 | /// <summary> |
75 | /// Read the next entry in the tar file. | 75 | /// Read the next entry in the tar file. |
76 | /// </summary> | 76 | /// </summary> |
@@ -79,27 +79,27 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
79 | public byte[] ReadEntry(out string filePath) | 79 | public byte[] ReadEntry(out string filePath) |
80 | { | 80 | { |
81 | filePath = String.Empty; | 81 | filePath = String.Empty; |
82 | 82 | ||
83 | if (AtEof()) | 83 | if (AtEof()) |
84 | return null; | 84 | return null; |
85 | 85 | ||
86 | TarHeader header = ReadHeader(); | 86 | TarHeader header = ReadHeader(); |
87 | 87 | ||
88 | filePath = header.FilePath; | 88 | filePath = header.FilePath; |
89 | byte[] data = m_br.ReadBytes(header.FileSize); | 89 | byte[] data = m_br.ReadBytes(header.FileSize); |
90 | 90 | ||
91 | m_log.DebugFormat("[TAR ARCHIVE READER]: filePath {0}, fileSize {1}", filePath, header.FileSize); | 91 | m_log.DebugFormat("[TAR ARCHIVE READER]: filePath {0}, fileSize {1}", filePath, header.FileSize); |
92 | 92 | ||
93 | // Read the rest of the empty padding in the 512 byte block | 93 | // Read the rest of the empty padding in the 512 byte block |
94 | if (header.FileSize % 512 != 0) | 94 | if (header.FileSize % 512 != 0) |
95 | { | 95 | { |
96 | int paddingLeft = 512 - (header.FileSize % 512); | 96 | int paddingLeft = 512 - (header.FileSize % 512); |
97 | 97 | ||
98 | m_log.DebugFormat("[TAR ARCHIVE READER]: Reading {0} padding bytes", paddingLeft); | 98 | m_log.DebugFormat("[TAR ARCHIVE READER]: Reading {0} padding bytes", paddingLeft); |
99 | 99 | ||
100 | m_br.ReadBytes(paddingLeft); | 100 | m_br.ReadBytes(paddingLeft); |
101 | } | 101 | } |
102 | 102 | ||
103 | return data; | 103 | return data; |
104 | } | 104 | } |
105 | 105 | ||
@@ -109,44 +109,44 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver | |||
109 | /// </summary> | 109 | /// </summary> |
110 | /// <returns>A tar header struct.</returns> | 110 | /// <returns>A tar header struct.</returns> |
111 | protected TarHeader ReadHeader() | 111 | protected TarHeader ReadHeader() |
112 | { | 112 | { |
113 | TarHeader tarHeader = new TarHeader(); | 113 | TarHeader tarHeader = new TarHeader(); |
114 | 114 | ||
115 | byte[] header = m_br.ReadBytes(512); | 115 | byte[] header = m_br.ReadBytes(512); |
116 | 116 | ||
117 | tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); | 117 | tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); |
118 | tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); | 118 | tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); |
119 | tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11); | 119 | tarHeader.FileSize = ConvertOctalBytesToDecimal(header, 124, 11); |
120 | 120 | ||
121 | return tarHeader; | 121 | return tarHeader; |
122 | } | 122 | } |
123 | 123 | ||
124 | public void Close() | 124 | public void Close() |
125 | { | 125 | { |
126 | m_br.Close(); | 126 | m_br.Close(); |
127 | } | 127 | } |
128 | 128 | ||
129 | /// <summary> | 129 | /// <summary> |
130 | /// Convert octal bytes to a decimal representation | 130 | /// Convert octal bytes to a decimal representation |
131 | /// </summary> | 131 | /// </summary> |
132 | /// <param name="bytes"></param> | 132 | /// <param name="bytes"></param> |
133 | /// <returns></returns> | 133 | /// <returns></returns> |
134 | public static int ConvertOctalBytesToDecimal(byte[] bytes, int startIndex, int count) | 134 | public static int ConvertOctalBytesToDecimal(byte[] bytes, int startIndex, int count) |
135 | { | 135 | { |
136 | string oString = m_asciiEncoding.GetString(bytes, startIndex, count); | 136 | string oString = m_asciiEncoding.GetString(bytes, startIndex, count); |
137 | 137 | ||
138 | int d = 0; | 138 | int d = 0; |
139 | 139 | ||
140 | foreach (char c in oString) | 140 | foreach (char c in oString) |
141 | { | 141 | { |
142 | d <<= 3; | 142 | d <<= 3; |
143 | d |= c - '0'; | 143 | d |= c - '0'; |
144 | } | 144 | } |
145 | 145 | ||
146 | return d; | 146 | return d; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | public struct TarHeader | 150 | public struct TarHeader |
151 | { | 151 | { |
152 | public string FilePath; | 152 | public string FilePath; |