use of java.io.FileInputStream in project druid by druid-io.
the class GenericIndexedWriter method writeToChannelVersionTwo.
private void writeToChannelVersionTwo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException {
if (smoosher == null) {
throw new IAE("version 2 GenericIndexedWriter requires FileSmoosher.");
}
int bagSizePower = bagSizePower();
OutputStream metaOut = Channels.newOutputStream(channel);
metaOut.write(GenericIndexed.VERSION_TWO);
metaOut.write(objectsSorted ? 0x1 : 0x0);
metaOut.write(Ints.toByteArray(bagSizePower));
metaOut.write(Ints.toByteArray(Ints.checkedCast(numWritten)));
metaOut.write(Ints.toByteArray(fileNameByteArray.length));
metaOut.write(fileNameByteArray);
try (RandomAccessFile headerFile = new RandomAccessFile(ioPeon.getFile(makeFilename("headerLong")), "r")) {
Preconditions.checkNotNull(headerFile, "header file missing.");
long previousValuePosition = 0;
int bagSize = 1 << bagSizePower;
int numberOfFilesRequired = GenericIndexed.getNumberOfFilesRequired(bagSize, numWritten);
byte[] buffer = new byte[1 << 16];
try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("values")))) {
int counter = -1;
for (int i = 0; i < numberOfFilesRequired; i++) {
if (i != numberOfFilesRequired - 1) {
// 8 for long bytes.
headerFile.seek((bagSize + counter) * Longs.BYTES);
counter = counter + bagSize;
} else {
// for remaining items.
headerFile.seek((numWritten - 1) * Longs.BYTES);
}
long valuePosition = Long.reverseBytes(headerFile.readLong());
long numBytesToPutInFile = valuePosition - previousValuePosition;
try (SmooshedWriter smooshChannel = smoosher.addWithSmooshedWriter(generateValueFileName(filenameBase, i), numBytesToPutInFile)) {
writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is);
previousValuePosition = valuePosition;
}
}
}
writeHeaderLong(smoosher, headerFile, bagSizePower, buffer);
}
}
use of java.io.FileInputStream in project druid by druid-io.
the class GenericIndexedWriter method writeHeaderLong.
private void writeHeaderLong(FileSmoosher smoosher, RandomAccessFile headerFile, int bagSizePower, byte[] buffer) throws IOException {
ByteBuffer helperBuffer = ByteBuffer.allocate(Ints.BYTES).order(ByteOrder.nativeOrder());
try (CountingOutputStream finalHeaderOut = new CountingOutputStream(ioPeon.makeOutputStream(makeFilename("header_final")))) {
int numberOfElementsPerValueFile = 1 << bagSizePower;
long currentNumBytes = 0;
long relativeRefBytes = 0;
long relativeNumBytes;
headerFile.seek(0);
// following block converts long header indexes into int header indexes.
for (int pos = 0; pos < numWritten; pos++) {
// to current offset.
if ((pos & (numberOfElementsPerValueFile - 1)) == 0) {
relativeRefBytes = currentNumBytes;
}
currentNumBytes = Long.reverseBytes(headerFile.readLong());
relativeNumBytes = currentNumBytes - relativeRefBytes;
writeIntValueToOutputStream(helperBuffer, Ints.checkedCast(relativeNumBytes), finalHeaderOut);
}
long numBytesToPutInFile = finalHeaderOut.getCount();
finalHeaderOut.close();
try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("header_final")))) {
try (SmooshedWriter smooshChannel = smoosher.addWithSmooshedWriter(generateHeaderFileName(filenameBase), numBytesToPutInFile)) {
writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is);
}
}
}
}
use of java.io.FileInputStream in project che by eclipse.
the class ApiEndpointAccessibilityChecker method start.
@PostConstruct
public void start() {
try {
final HttpJsonResponse pingResponse = httpJsonRequestFactory.fromUrl(apiEndpoint).setMethod(HttpMethod.GET).setTimeout(2000).request();
if (pingResponse.getResponseCode() == HttpURLConnection.HTTP_OK) {
return;
}
} catch (ApiException | IOException e) {
LOG.error(e.getLocalizedMessage(), e);
}
LOG.error("The workspace agent has attempted to start, but it is unable to ping the Che server at " + apiEndpoint);
LOG.error("The workspace agent has been forcefully stopped. " + "This error happens when the agent cannot resolve the location of the Che server. " + "This error can usually be fixed with additional configuration settings in /conf/che.properties. " + "The Che server will stop this workspace after a short timeout. " + "You can get help by posting your config, stacktrace and workspace /etc/hosts below as a GitHub issue.");
// content of /etc/hosts file may provide clues on why the connection failed, e.g. how che-host is resolved
try {
LOG.info("Workspace /etc/hosts: " + IoUtil.readAndCloseQuietly(new FileInputStream(new File("/etc/hosts"))));
} catch (Exception e) {
LOG.info(e.getLocalizedMessage(), e);
}
System.exit(0);
}
use of java.io.FileInputStream in project jetty.project by eclipse.
the class DigestPostTest method testServerWithHttpClientStreamContent.
@Test
public void testServerWithHttpClientStreamContent() throws Exception {
String srvUrl = "http://127.0.0.1:" + ((NetworkConnector) _server.getConnectors()[0]).getLocalPort() + "/test/";
HttpClient client = new HttpClient();
try {
AuthenticationStore authStore = client.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
client.start();
String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
Request request = client.newRequest(srvUrl);
request.method(HttpMethod.POST);
request.content(new StringContentProvider(sent));
_received = null;
request = request.timeout(5, TimeUnit.SECONDS);
ContentResponse response = request.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(sent, _received);
} finally {
client.stop();
}
}
use of java.io.FileInputStream in project che by eclipse.
the class DeltaProcessingState method getExternalLibTimeStamps.
public Hashtable getExternalLibTimeStamps() {
if (this.externalTimeStamps == null) {
Hashtable timeStamps = new Hashtable();
File timestampsFile = getTimeStampsFile();
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(timestampsFile)));
int size = in.readInt();
while (size-- > 0) {
String key = in.readUTF();
long timestamp = in.readLong();
timeStamps.put(Path.fromPortableString(key), new Long(timestamp));
}
} catch (IOException e) {
if (timestampsFile.exists())
//$NON-NLS-1$
Util.log(e, "Unable to read external time stamps");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// nothing we can do: ignore
}
}
}
this.externalTimeStamps = timeStamps;
}
return this.externalTimeStamps;
}
Aggregations