Skip to content

Commit 8997782

Browse files
ctruedengab1one
authored andcommitted
Add DummyLocation and DummyHandle
1 parent 558325e commit 8997782

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* #%L
3+
* SciJava Common shared library for SciJava software.
4+
* %%
5+
* Copyright (C) 2009 - 2017 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.io;
33+
34+
import java.io.IOException;
35+
import java.util.Arrays;
36+
37+
import org.scijava.plugin.Plugin;
38+
39+
/**
40+
* A {@link DataHandle} which reads all zeroes, and writes no actual data.
41+
*
42+
* @author Curtis Rueden
43+
*/
44+
@Plugin(type = DataHandle.class)
45+
public class DummyHandle extends AbstractDataHandle<DummyLocation> {
46+
47+
// -- Fields --
48+
49+
private long offset;
50+
private long length;
51+
52+
// -- DataHandle methods --
53+
54+
@Override
55+
public long offset() throws IOException {
56+
return offset;
57+
}
58+
59+
@Override
60+
public void seek(final long pos) throws IOException {
61+
if (pos > length()) setLength(pos);
62+
offset = pos;
63+
}
64+
65+
@Override
66+
public long length() throws IOException {
67+
return length;
68+
}
69+
70+
@Override
71+
public void setLength(final long length) throws IOException {
72+
this.length = length;
73+
}
74+
75+
@Override
76+
public boolean isReadable() {
77+
return true;
78+
}
79+
80+
@Override
81+
public boolean isWritable() {
82+
return true;
83+
}
84+
85+
@Override
86+
public byte readByte() throws IOException {
87+
final long r = available(1);
88+
if (r <= 0) return -1;
89+
offset++;
90+
return 0;
91+
}
92+
93+
@Override
94+
public int read(final byte[] b, final int off, final int len)
95+
throws IOException
96+
{
97+
final int r = (int) available(len);
98+
offset += r;
99+
Arrays.fill(b, off, off + r, (byte) 0);
100+
return r;
101+
}
102+
103+
// -- DataOutput methods --
104+
105+
@Override
106+
public void write(final int v) throws IOException {
107+
ensureWritable(1);
108+
offset++;
109+
}
110+
111+
@Override
112+
public void write(final byte[] b, final int off, final int len)
113+
throws IOException
114+
{
115+
ensureWritable(len);
116+
offset += len;
117+
}
118+
119+
// -- Closeable methods --
120+
121+
@Override
122+
public void close() {
123+
// NB: No action needed.
124+
}
125+
126+
// -- Typed methods --
127+
128+
@Override
129+
public Class<DummyLocation> getType() {
130+
return DummyLocation.class;
131+
}
132+
133+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* #%L
3+
* SciJava Common shared library for SciJava software.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.io;
33+
34+
/**
35+
* {@link Location} backed by nothing whatsoever.
36+
*
37+
* @author Curtis Rueden
38+
* @see DummyHandle
39+
*/
40+
public class DummyLocation extends AbstractLocation {
41+
// NB: No implementation needed.
42+
}

0 commit comments

Comments
 (0)