/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4434723 4482726 4559072 4638365 4795550 5081340 5103988 6253145
* 6984545
* @summary Test FileChannel.transferFrom and transferTo
* @library ..
*/
public class Transfer {
private static int[] testSizes = {
0, 10, 1023, 1024, 1025, 2047, 2048, 2049 };
xferTest02(); // for bug 4482726
xferTest03(); // for bug 4559072
xferTest04(); // for bug 4638365
xferTest05(); // for bug 4638365
xferTest06(); // for bug 5081340
xferTest07(); // for bug 5103988
xferTest08(); // for bug 6253145
xferTest09(); // for bug 6984545
}
sink.deleteOnExit();
"Use the source, Luke!".getBytes()));
if (bytesWritten != 10)
throw new RuntimeException("Transfer failed");
throw new RuntimeException("Source position didn't change");
throw new RuntimeException("Sink position changed");
throw new RuntimeException("Unexpected sink size");
if (bytesWritten > 0)
throw new RuntimeException("Wrote past file size");
sinkChannel.close();
}
sink.configureBlocking(false);
outgoingdata.flip();
int totalWritten = 0;
if (written < 0)
throw new Exception("Write failed");
totalWritten += written;
}
f.deleteOnExit();
if (bytesWritten != size)
throw new RuntimeException("Transfer failed");
throw new RuntimeException("Position changed");
f.delete();
}
byte[] srcData = new byte[5000];
for (int i=0; i<5000; i++)
// get filechannel for the source file.
// write out data to the file channel
long bytesWritten = 0;
while (bytesWritten < 5000) {
}
// get filechannel for the dst file.
dest.deleteOnExit();
int bytesToWrite = 3000;
int startPosition = 1000;
}
// get filechannel for the source file.
// write out data to the file channel
int bytesWritten = 0;
while (bytesWritten < 4) {
}
// get filechannel for the dst file.
dest.deleteOnExit();
throw new Exception("xferTest03 failed");
}
// Test transferTo with large file
// Windows and Linux can't handle the really large file sizes for a
// truncate or a positional write required by the test for 4563125
return;
sink.deleteOnExit();
if (bytesWritten != 10) {
throw new RuntimeException("Transfer test 4 failed " +
}
sinkChannel.close();
}
// Test transferFrom with large file
// Create a source file & large sink file for the test
// Create the sink file as a sparse file if possible
// re-create as a sparse file
try {
} catch (FileAlreadyExistsException ignore) {
// someone else got it
}
}
sink.deleteOnExit();
try {
testSize - 40);
} catch (IOException e) {
// Can't set up the test, abort it
return;
} finally {
}
// Get new channels for the source and sink and attempt transfer
try {
try {
if (bytesWritten != 10) {
throw new RuntimeException("Transfer test 5 failed " +
}
} finally {
sinkChannel.close();
}
} finally {
}
}
int c;
while ((c = r.read()) != -1)
+ ", got: " + contents);
r.close();
}
// Test transferFrom asking for more bytes than remain in source
sink.deleteOnExit();
if (n != remaining)
sinkChannel.close();
}
// Test transferTo to non-blocking socket channel
.getChannel();
// The sink is a non-blocking socket channel
sink.configureBlocking(false);
// keep sending until congested
long n;
do {
} while (n > 0);
}
// Test transferTo with file positions larger than 2 and 4GB
// Creating a sparse 6GB file on Windows takes too long
return;
final long G = 1024L * 1024L * 1024L;
// Create 6GB file
file.deleteOnExit();
try {
} catch (IOException x) {
return;
}
// Setup looback connection and echo server
// Test data is array of positions and counts
long testdata[][] = {
{ 2*G-1, 1 },
{ 2*G-1, 10 }, // across 2GB boundary
{ 2*G, 1 },
{ 2*G, 10 },
{ 2*G+1, 1 },
{ 4*G-1, 1 },
{ 4*G-1, 10 }, // across 4GB boundary
{ 4*G, 1 },
{ 4*G, 10 },
{ 4*G+1, 1 },
{ 5*G-1, 1 },
{ 5*G-1, 10 },
{ 5*G, 1 },
{ 5*G, 10 },
{ 5*G+1, 1 },
{ 6*G, 1 },
};
try {
byte value = 0;
// generate bytes
for (long j=0; j<count; j++) {
}
// write to file and transfer to echo server
// read from echo server
long nread = 0;
if (n < 0)
throw new RuntimeException("Premature EOF!");
nread += n;
}
// check reply from echo server
throw new RuntimeException("Echo'ed bytes do not match!");
}
} finally {
}
}
// Test that transferFrom with FileChannel source that is not readable
// throws NonReadableChannelException
try {
throw new RuntimeException("NonReadableChannelException expected");
} catch (NonReadableChannelException expected) {
} finally {
}
}
/**
* Creates file blah of specified size in bytes.
*/
for(int i=0; i<size; i++) {
}
}
/**
* Simple in-process server to echo bytes read by a given socket channel
*/
}
public void run() {
try {
for (;;) {
if (n < 0)
break;
}
}
} catch (IOException x) {
x.printStackTrace();
} finally {
try {
} catch (IOException ignore) { }
}
}
}
}