Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/RiffReaderWriter/Skip.java
38862 views
1
/*
2
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
@summary Test RiffReader skip method */
26
27
import java.io.File;
28
import java.io.FileInputStream;
29
30
import com.sun.media.sound.RIFFReader;
31
import com.sun.media.sound.RIFFWriter;
32
33
public class Skip {
34
35
private static void assertEquals(Object a, Object b) throws Exception
36
{
37
if(!a.equals(b))
38
throw new RuntimeException("assertEquals fails!");
39
}
40
41
public static void main(String[] args) throws Exception {
42
test(false);
43
test(true);
44
}
45
46
private static void test(boolean customStream) throws Exception {
47
RIFFWriter writer = null;
48
RIFFReader reader = null;
49
File tempfile = File.createTempFile("test",".riff");
50
try
51
{
52
writer = new RIFFWriter(tempfile, "TEST");
53
RIFFWriter chunk = writer.writeChunk("TSCH");
54
chunk.write((byte)33);
55
chunk.write((byte)44);
56
writer.close();
57
writer = null;
58
final FileInputStream fis;
59
if (customStream) {
60
fis = new FileInputStream(tempfile);
61
} else {
62
fis = new FileInputStream(tempfile) {
63
@Override
64
public long skip(long n) {
65
return 0;
66
}
67
};
68
}
69
reader = new RIFFReader(fis);
70
RIFFReader readchunk = reader.nextChunk();
71
reader.skip(1);
72
assertEquals(readchunk.read(), 44);
73
fis.close();
74
reader = null;
75
76
77
}
78
finally
79
{
80
if(writer != null)
81
writer.close();
82
if(reader != null)
83
reader.close();
84
85
if(tempfile.exists())
86
if(!tempfile.delete())
87
tempfile.deleteOnExit();
88
}
89
}
90
}
91
92