From 9fbfe2b98e0c3fd921205bdac8d5d83fe35bd7a0 Mon Sep 17 00:00:00 2001 From: cpw Date: Mon, 28 Jan 2019 20:37:08 -0500 Subject: [PATCH] Fix 5408 by making Paths from the default provider (not inside jars) offer a FileInputStream rather than Files.newInputStream. Fun. Stupid ancient paulscode. Signed-off-by: cpw --- .../fml/packs/ModFileResourcePack.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java index 5a83d7fa18..362a141b53 100644 --- a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java +++ b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java @@ -19,6 +19,7 @@ package net.minecraftforge.fml.packs; +import it.unimi.dsi.fastutil.io.FastByteArrayInputStream; import net.minecraft.resources.AbstractResourcePack; import net.minecraft.resources.ResourcePackInfo; import net.minecraft.resources.ResourcePackType; @@ -26,11 +27,13 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.loading.moddiscovery.ModFile; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.channels.ByteChannel; +import java.nio.channels.Channels; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.*; import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -64,7 +67,16 @@ public class ModFileResourcePack extends AbstractResourcePack @Override protected InputStream getInputStream(String name) throws IOException { - return Files.newInputStream(modFile.getLocator().findPath(modFile, name)); + // because paulscode is ancient, we can't return FileChannel based InputStreams here - it will cause a deadlock or crash + // Paulscode sends interrupt() to trigger thread processing behaviour, and FileChannels will interpret that interrupt() as + // a sign to close the FileChannel and throw an interrupt error. Tis brilliant! + // If the Path comes from the default filesystem provider, we will rather use the path to generate an old FileInputStream + final Path path = modFile.getLocator().findPath(modFile, name); + if (path.getFileSystem() == FileSystems.getDefault()) { + return new FileInputStream(path.toFile()); + } else { + return Files.newInputStream(path, StandardOpenOption.READ); + } } @Override