IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ClassStubZipEntry.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2007-2015 Jeroen Frijters
3 Copyright (C) 2009 Volker Berlin (i-net software)
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20
21 Jeroen Frijters
22 jeroen@frijters.net
23
24*/
25using System;
26using System.IO;
27
28using IKVM.Runtime;
30
32{
33
34 static class ClassStubZipEntry
35 {
36
37#if !FIRST_PASS
38
42 sealed class ZipEntryStream : Stream
43 {
44
45 readonly global::java.util.zip.ZipFile zipFile;
46 readonly global::java.util.zip.ZipEntry entry;
47 global::java.io.InputStream inp;
48 long position;
49
55 public ZipEntryStream(global::java.util.zip.ZipFile zipFile, global::java.util.zip.ZipEntry entry)
56 {
57 this.zipFile = zipFile;
58 this.entry = entry;
59 inp = zipFile.getInputStream(entry);
60 }
61
62 public override bool CanRead
63 {
64 get { return true; }
65 }
66
67 public override bool CanWrite
68 {
69 get { return false; }
70 }
71
72 public override bool CanSeek
73 {
74 get { return true; }
75 }
76
77 public override long Length
78 {
79 get { return entry.getSize(); }
80 }
81
82 public override int Read(byte[] buffer, int offset, int count)
83 {
84 // For compatibility with real file i/o, we try to read the requested number
85 // of bytes, instead of returning earlier if the underlying InputStream does so.
86 var totalRead = 0;
87 while (count > 0)
88 {
89 var read = inp.read(buffer, offset, count);
90 if (read <= 0)
91 break;
92
93 offset += read;
94 count -= read;
95 totalRead += read;
96 position += read;
97 }
98
99 return totalRead;
100 }
101
102 public override long Position
103 {
104 get
105 {
106 return position;
107 }
108 set
109 {
110 if (value < position)
111 {
112 if (value < 0)
113 throw new System.IO.IOException("Negative seek offset");
114
115 position = 0;
116 inp.close();
117 inp = zipFile.getInputStream(entry);
118 }
119
120 var skip = value - position;
121 while (skip > 0)
122 {
123 var skipped = inp.skip(skip);
124 if (skipped == 0)
125 {
126 if (position != entry.getSize())
127 throw new System.IO.IOException("skip failed");
128
129 // we're actually at EOF in the InputStream, but we set the virtual position beyond EOF
130 position += skip;
131 break;
132 }
133 position += skipped;
134 skip -= skipped;
135 }
136 }
137 }
138
139 public override void Flush()
140 {
141
142 }
143
144 public override long Seek(long offset, SeekOrigin origin)
145 {
146 switch (origin)
147 {
148 case SeekOrigin.Begin:
149 Position = offset;
150 break;
151 case SeekOrigin.Current:
152 Position += offset;
153 break;
154 case SeekOrigin.End:
155 Position = entry.getSize() + offset;
156 break;
157 }
158
159 return position;
160 }
161
162 public override void Write(byte[] buffer, int offset, int count)
163 {
164 throw new NotSupportedException();
165 }
166
167 public override void SetLength(long value)
168 {
169 throw new NotSupportedException();
170 }
171
172 public override void Close()
173 {
174 base.Close();
175 inp.close();
176 }
177
178 }
179
180#endif
181
187 public static void expandIkvmClasses(object _zipFile, object _entries)
188 {
189#if FIRST_PASS
190 throw new NotImplementedException();
191#else
192 var zipFile = (global::java.util.zip.ZipFile)_zipFile;
193 var entries = (global::java.util.LinkedHashMap)_entries;
194
195 try
196 {
197 var path = zipFile.getName();
198 if (JVM.Vfs.IsPath(path))
199 {
200 var entry = (global::java.util.zip.ZipEntry)entries.get(JVM.Internal.JarClassList);
201 if (entry != null)
202 {
203 using var stream = new ZipEntryStream(zipFile, entry);
204 entries.remove(entry.name);
205
206 var br = new BinaryReader(stream);
207 var count = br.ReadInt32();
208 for (int i = 0; i < count; i++)
209 {
210 var classEntry = new global::java.util.zip.ClassStubZipEntry(path, br.ReadString());
211 classEntry.setMethod(global::java.util.zip.ClassStubZipEntry.STORED);
212 classEntry.setTime(entry.getTime());
213 entries.put(classEntry.name, classEntry);
214 }
215 }
216 }
217 }
218 catch (global::java.io.IOException)
219 {
220
221 }
222 catch (IOException)
223 {
224
225 }
226#endif
227 }
228
229 }
230
231}
static void expandIkvmClasses(object _zipFile, object _entries)
Implements the native method for 'expandIkvmClasses'.
Main state of the running JVM.