Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 1262ce5

Browse files
committed
Added OutputStream.nullOutputStream() MCR
1 parent 672bee0 commit 1262ce5

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* MIT License
3+
*
4+
* This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader
5+
* Copyright (c) 2023 RK_01/RaphiMC and contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
package net.raphimc.javadowngrader.runtime;
26+
27+
import java.io.IOException;
28+
import java.io.OutputStream;
29+
30+
public class NullOutputStream extends OutputStream {
31+
32+
private volatile boolean closed = false;
33+
34+
@Override
35+
public void write(int b) throws IOException {
36+
if (this.closed) {
37+
throw new IOException("Stream closed");
38+
}
39+
}
40+
41+
@Override
42+
public void close() {
43+
this.closed = true;
44+
}
45+
46+
}

src/main/java/net/raphimc/javadowngrader/transformer/j10/Java11ToJava10.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public Java11ToJava10() {
4747

4848
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/util/zip/Inflater", "setInput", "(Ljava/nio/ByteBuffer;)V", new InflaterSetInputMCR());
4949
this.addMethodCallReplacer(Opcodes.INVOKEVIRTUAL, "java/util/zip/Inflater", "inflate", "(Ljava/nio/ByteBuffer;)I", new InflaterInflateMCR());
50+
51+
this.addMethodCallReplacer(Opcodes.INVOKESTATIC, "java/io/OutputStream", "nullOutputStream", "()Ljava/io/OutputStream;", new OutputStreamNullOutputStreamMCR());
5052
}
5153

5254
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of JavaDowngrader - https://github.com/RaphiMC/JavaDowngrader
3+
* Copyright (C) 2023 RK_01/RaphiMC and contributors
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package net.raphimc.javadowngrader.transformer.j10.methodcallreplacer;
19+
20+
import net.raphimc.javadowngrader.RuntimeDepCollector;
21+
import net.raphimc.javadowngrader.transformer.DowngradeResult;
22+
import net.raphimc.javadowngrader.transformer.MethodCallReplacer;
23+
import org.objectweb.asm.Opcodes;
24+
import org.objectweb.asm.tree.*;
25+
26+
public class OutputStreamNullOutputStreamMCR implements MethodCallReplacer {
27+
28+
@Override
29+
public InsnList getReplacement(ClassNode classNode, MethodNode method, String originalName, String originalDesc, RuntimeDepCollector depCollector, DowngradeResult result) {
30+
depCollector.accept("net/raphimc/javadowngrader/runtime/NullOutputStream");
31+
32+
final InsnList replacement = new InsnList();
33+
34+
//
35+
replacement.add(new TypeInsnNode(Opcodes.NEW, "net/raphimc/javadowngrader/runtime/NullOutputStream"));
36+
replacement.add(new InsnNode(Opcodes.DUP));
37+
replacement.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/raphimc/javadowngrader/runtime/NullOutputStream", "<init>", "()V"));
38+
// OutputStream
39+
40+
return replacement;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)