FileResourcePack .java

net.minecraft.client.resources.FileResourcePack (class, 123 lines): members: resourcePackZipFile, entryNameSplitter, finalize, close, getInputStreamByName.

net.minecraft.client.resourcesclass123 linesclientextends AbstractResourcePack3.1 KB

Implements

API Surface (5)

InputStream getInputStreamByName(String name)
boolean hasResourceName(String name)
Set<String> getResourceDomains()
void finalize()
void close()

Fields & Constants (2)

entryNameSplitter
resourcePackZipFile

String literals (1)

"assets/"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

FileResourcePack.java123 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.resources;
2
3
import com.google.common.base.Splitter;
4
import com.google.common.collect.Lists;
5
import com.google.common.collect.Sets;
6
import java.io.Closeable;
7
import java.io.File;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.util.Collections;
11
import java.util.Enumeration;
12
import java.util.List;
13
import java.util.Set;
14
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipFile;
16
17
public class FileResourcePack extends AbstractResourcePack implements Closeable
18
{
19
    public static final Splitter entryNameSplitter = Splitter.on('/').omitEmptyStrings().limit(3);
20
    private ZipFile resourcePackZipFile;
21
22
    public FileResourcePack(File resourcePackFileIn)
23
    {
24
        super(resourcePackFileIn);
25
    }
26
27
    private ZipFile getResourcePackZipFile() throws IOException
28
    {
29
        if (this.resourcePackZipFile == null)
30
        {
31
            this.resourcePackZipFile = new ZipFile(this.resourcePackFile);
32
        }
33
34
        return this.resourcePackZipFile;
35
    }
36
37
    protected InputStream getInputStreamByName(String name) throws IOException
38
    {
39
        ZipFile zipfile = this.getResourcePackZipFile();
40
        ZipEntry zipentry = zipfile.getEntry(name);
41
42
        if (zipentry == null)
43
        {
44
            throw new ResourcePackFileNotFoundException(this.resourcePackFile, name);
45
        }
46
        else
47
        {
48
            return zipfile.getInputStream(zipentry);
49
        }
50
    }
51
52
    public boolean hasResourceName(String name)
53
    {
54
        try
55
        {
56
            return this.getResourcePackZipFile().getEntry(name) != null;
57
        }
58
        catch (IOException var3)
59
        {
60
            return false;
61
        }
62
    }
63
64
    public Set<String> getResourceDomains()
65
    {
66
        ZipFile zipfile;
67
68
        try
69
        {
70
            zipfile = this.getResourcePackZipFile();
71
        }
72
        catch (IOException var8)
73
        {
74
            return Collections.<String>emptySet();
75
        }
76
77
        Enumeration <? extends ZipEntry > enumeration = zipfile.entries();
78
        Set<String> set = Sets.<String>newHashSet();
79
80
        while (enumeration.hasMoreElements())
81
        {
82
            ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
83
            String s = zipentry.getName();
84
85
            if (s.startsWith("assets/"))
86
            {
87
                List<String> list = Lists.newArrayList(entryNameSplitter.split(s));
88
89
                if (list.size() > 1)
90
                {
91
                    String s1 = (String)list.get(1);
92
93
                    if (!s1.equals(s1.toLowerCase()))
94
                    {
95
                        this.logNameNotLowercase(s1);
96
                    }
97
                    else
98
                    {
99
                        set.add(s1);
100
                    }
101
                }
102
            }
103
        }
104
105
        return set;
106
    }
107
108
    protected void finalize() throws Throwable
109
    {
110
        this.close();
111
        super.finalize();
112
    }
113
114
    public void close() throws IOException
115
    {
116
        if (this.resourcePackZipFile != null)
117
        {
118
            this.resourcePackZipFile.close();
119
            this.resourcePackZipFile = null;
120
        }
121
    }
122
}
123

Deobfuscated MCP 1.8.9 source of FileResourcePack from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/resources/FileResourcePack.java), stored verbatim.