FallbackResourceManager .java

net.minecraft.client.resources.FallbackResourceManager (class): members: InputStreamLeakedResourceLogger, frmMetadataSerializer, addResourcePack, logger.

net.minecraft.client.resourcesclass138 linesclient4.8 KB

Implements

API Surface (8)

void addResourcePack(IResourcePack resourcePack)
Set<String> getResourceDomains()
IResource getResource(ResourceLocation location)
InputStream getInputStream(ResourceLocation location, IResourcePack resourcePack)
List<IResource> getAllResources(ResourceLocation location)
void close()
void finalize()
int read()

Fields & Constants (3)

logger
resourcePacks
frmMetadataSerializer

String literals (3)

".mcmeta"
"Leaked resource: \'"
"\' loaded from pack: \'"

Code Graph: Dependencies (5)

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

Full Source

FallbackResourceManager.java138 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.resources;
2
3
import com.google.common.collect.Lists;
4
import java.io.ByteArrayOutputStream;
5
import java.io.FileNotFoundException;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.io.PrintStream;
9
import java.util.List;
10
import java.util.Set;
11
import net.minecraft.client.resources.data.IMetadataSerializer;
12
import net.minecraft.util.ResourceLocation;
13
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.Logger;
15
16
public class FallbackResourceManager implements IResourceManager
17
{
18
    private static final Logger logger = LogManager.getLogger();
19
    protected final List<IResourcePack> resourcePacks = Lists.<IResourcePack>newArrayList();
20
    private final IMetadataSerializer frmMetadataSerializer;
21
22
    public FallbackResourceManager(IMetadataSerializer frmMetadataSerializerIn)
23
    {
24
        this.frmMetadataSerializer = frmMetadataSerializerIn;
25
    }
26
27
    public void addResourcePack(IResourcePack resourcePack)
28
    {
29
        this.resourcePacks.add(resourcePack);
30
    }
31
32
    public Set<String> getResourceDomains()
33
    {
34
        return null;
35
    }
36
37
    public IResource getResource(ResourceLocation location) throws IOException
38
    {
39
        IResourcePack iresourcepack = null;
40
        ResourceLocation resourcelocation = getLocationMcmeta(location);
41
42
        for (int i = this.resourcePacks.size() - 1; i >= 0; --i)
43
        {
44
            IResourcePack iresourcepack1 = (IResourcePack)this.resourcePacks.get(i);
45
46
            if (iresourcepack == null && iresourcepack1.resourceExists(resourcelocation))
47
            {
48
                iresourcepack = iresourcepack1;
49
            }
50
51
            if (iresourcepack1.resourceExists(location))
52
            {
53
                InputStream inputstream = null;
54
55
                if (iresourcepack != null)
56
                {
57
                    inputstream = this.getInputStream(resourcelocation, iresourcepack);
58
                }
59
60
                return new SimpleResource(iresourcepack1.getPackName(), location, this.getInputStream(location, iresourcepack1), inputstream, this.frmMetadataSerializer);
61
            }
62
        }
63
64
        throw new FileNotFoundException(location.toString());
65
    }
66
67
    protected InputStream getInputStream(ResourceLocation location, IResourcePack resourcePack) throws IOException
68
    {
69
        InputStream inputstream = resourcePack.getInputStream(location);
70
        return (InputStream)(logger.isDebugEnabled() ? new FallbackResourceManager.InputStreamLeakedResourceLogger(inputstream, location, resourcePack.getPackName()) : inputstream);
71
    }
72
73
    public List<IResource> getAllResources(ResourceLocation location) throws IOException
74
    {
75
        List<IResource> list = Lists.<IResource>newArrayList();
76
        ResourceLocation resourcelocation = getLocationMcmeta(location);
77
78
        for (IResourcePack iresourcepack : this.resourcePacks)
79
        {
80
            if (iresourcepack.resourceExists(location))
81
            {
82
                InputStream inputstream = iresourcepack.resourceExists(resourcelocation) ? this.getInputStream(resourcelocation, iresourcepack) : null;
83
                list.add(new SimpleResource(iresourcepack.getPackName(), location, this.getInputStream(location, iresourcepack), inputstream, this.frmMetadataSerializer));
84
            }
85
        }
86
87
        if (list.isEmpty())
88
        {
89
            throw new FileNotFoundException(location.toString());
90
        }
91
        else
92
        {
93
            return list;
94
        }
95
    }
96
97
    static ResourceLocation getLocationMcmeta(ResourceLocation location)
98
    {
99
        return new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + ".mcmeta");
100
    }
101
102
    static class InputStreamLeakedResourceLogger extends InputStream
103
    {
104
        private final InputStream inputStream;
105
        private final String message;
106
        private boolean isClosed = false;
107
108
        public InputStreamLeakedResourceLogger(InputStream p_i46093_1_, ResourceLocation location, String resourcePack)
109
        {
110
            this.inputStream = p_i46093_1_;
111
            ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
112
            (new Exception()).printStackTrace(new PrintStream(bytearrayoutputstream));
113
            this.message = "Leaked resource: \'" + location + "\' loaded from pack: \'" + resourcePack + "\'\n" + bytearrayoutputstream.toString();
114
        }
115
116
        public void close() throws IOException
117
        {
118
            this.inputStream.close();
119
            this.isClosed = true;
120
        }
121
122
        protected void finalize() throws Throwable
123
        {
124
            if (!this.isClosed)
125
            {
126
                FallbackResourceManager.logger.warn(this.message);
127
            }
128
129
            super.finalize();
130
        }
131
132
        public int read() throws IOException
133
        {
134
            return this.inputStream.read();
135
        }
136
    }
137
}
138

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