use of java.nio.channels.ClosedByInterruptException in project graal by oracle.
the class CSourceCodeWriter method writeFile.
public Path writeFile(String fileName, boolean ensureCorrectExtension) {
assert currentLine.length() == 0 : "last line not finished";
String fixedFileName = fileName;
if (!fileName.endsWith(C_SOURCE_FILE_EXTENSION) && ensureCorrectExtension) {
fixedFileName = fileName.concat(C_SOURCE_FILE_EXTENSION);
}
Path outputFile = tempDirectory.resolve(fixedFileName);
Charset charset = Charset.forName(CHARSET);
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, charset)) {
for (String line : lines) {
writer.write(line);
writer.write("\n");
}
} catch (ClosedByInterruptException ex) {
throw new InterruptImageBuilding();
} catch (IOException ex) {
throw shouldNotReachHere(ex);
}
return outputFile;
}
use of java.nio.channels.ClosedByInterruptException in project Bytecoder by mirkosertic.
the class FileChannelImpl method transferToTrustedChannel.
private long transferToTrustedChannel(long position, long count, WritableByteChannel target) throws IOException {
boolean isSelChImpl = (target instanceof SelChImpl);
if (!((target instanceof FileChannelImpl) || isSelChImpl))
return IOStatus.UNSUPPORTED;
// Trusted target: Use a mapped buffer
long remaining = count;
while (remaining > 0L) {
long size = Math.min(remaining, MAPPED_TRANSFER_SIZE);
try {
MappedByteBuffer dbb = map(MapMode.READ_ONLY, position, size);
try {
// ## Bug: Closing this channel will not terminate the write
int n = target.write(dbb);
assert n >= 0;
remaining -= n;
if (isSelChImpl) {
// one attempt to write to selectable channel
break;
}
assert n > 0;
position += n;
} finally {
unmap(dbb);
}
} catch (ClosedByInterruptException e) {
// to be thrown after closing this channel.
assert !target.isOpen();
try {
close();
} catch (Throwable suppressed) {
e.addSuppressed(suppressed);
}
throw e;
} catch (IOException ioe) {
// Only throw exception if no bytes have been written
if (remaining == count)
throw ioe;
break;
}
}
return count - remaining;
}
use of java.nio.channels.ClosedByInterruptException in project com.revolsys.open by revolsys.
the class ScaledIntegerGriddedDigitalElevationModelReader method read.
@Override
public GriddedElevationModel read() {
init();
if (this.exists) {
try {
final ChannelReader in = this.reader;
final int cellCount = this.gridWidth * this.gridHeight;
final int[] elevations = new int[cellCount];
final ReadableByteChannel channel = in.getChannel();
if (isMemoryMapped() && channel instanceof FileChannel) {
final FileChannel fileChannel = (FileChannel) channel;
final MappedByteBuffer mappedBytes = fileChannel.map(MapMode.READ_ONLY, ScaledIntegerGriddedDigitalElevation.HEADER_SIZE, cellCount * ScaledIntegerGriddedDigitalElevation.RECORD_SIZE);
final IntBuffer intBuffer = mappedBytes.asIntBuffer();
for (int index = 0; index < cellCount; index++) {
elevations[index] = intBuffer.get();
}
} else {
for (int index = 0; index < cellCount; index++) {
final int elevation = in.getInt();
elevations[index] = elevation;
}
}
final IntArrayScaleGriddedElevationModel elevationModel = new IntArrayScaleGriddedElevationModel(this.geometryFactory, this.boundingBox, this.gridWidth, this.gridHeight, this.gridCellSize, elevations);
elevationModel.setResource(this.resource);
return elevationModel;
} catch (final ClosedByInterruptException e) {
return null;
} catch (final IOException | RuntimeException e) {
if (Exceptions.isException(e, ClosedByInterruptException.class)) {
return null;
} else {
throw Exceptions.wrap("Unable to read DEM: " + this.resource, e);
}
}
} else {
return null;
}
}
use of java.nio.channels.ClosedByInterruptException in project h2database by h2database.
the class FileRetryOnInterrupt method reopen.
private void reopen(int i, IOException e) throws IOException {
if (i > 20) {
throw e;
}
if (!(e instanceof ClosedByInterruptException) && !(e instanceof ClosedChannelException)) {
throw e;
}
// clear the interrupt flag, to avoid re-opening many times
Thread.interrupted();
FileChannel before = channel;
// as this method is called in a loop
synchronized (this) {
if (before == channel) {
open();
reLock();
}
}
}
use of java.nio.channels.ClosedByInterruptException in project Purus-Pasta by puruscor.
the class HackSocket method release.
private void release() throws ClosedByInterruptException {
HackThread ut = (HackThread) Thread.currentThread();
InterruptAction ia = this.ia.get();
if (ia == null)
throw (new Error("Tried to release a hacked thread without an interrupt handler."));
ut.remil(ia);
if (ia.interrupted) {
ut.interrupt();
throw (new ClosedByInterruptException());
}
}
Aggregations