@Override public void close() throws IOException { if (null != dataOutStream) { CarbonUtil.closeStream(dataOutStream); } }
dataOutputStream.writeInt(fileData.length); dataOutputStream.write(fileData); CarbonUtil.closeStream(dataInputStream);
/** * This method closes the streams * * @param streams - streams to close. */ public static void closeStreams(Closeable... streams) { // Added if to avoid NullPointerException in case one stream is being passed as null if (null != streams) { for (Closeable stream : streams) { try { closeStream(stream); } catch (IOException e) { LOGGER.error("Error while closing stream:" + e, e); } } } }
/** * Close the file stream. */ public void close() throws IOException { closeAtomicFileWriter(); CarbonUtil.closeStream(dataOutputStream); }
/** * return the datainputStream which is seek to the offset of file * * @param path * @param fileType * @param bufferSize * @param offset * @return DataInputStream * @throws IOException */ @Override public DataInputStream getDataInputStream(String path, FileFactory.FileType fileType, int bufferSize, long offset) throws IOException { path = path.replace("\\", "/"); path = FileFactory.getUpdatedFilePath(path, fileType); FileInputStream fis = new FileInputStream(path); long actualSkipSize = 0; long skipSize = offset; try { while (actualSkipSize != offset) { actualSkipSize += fis.skip(skipSize); skipSize = skipSize - actualSkipSize; } } catch (IOException ioe) { CarbonUtil.closeStream(fis); throw ioe; } return new DataInputStream(new BufferedInputStream(fis)); }
@Override public void close() throws IOException { if (null != dataOutStream) { CarbonUtil.closeStream(dataOutStream); CarbonFile tempFile = FileFactory.getCarbonFile(tempWriteFilePath, fileType); if (!this.setFailed) { if (!tempFile.renameForce(filePath)) { throw new IOException( "temporary file renaming failed, src=" + tempFile.getPath() + ", dest=" + filePath); } } else { LOGGER.warn("The temporary file renaming skipped due to I/O error, deleting file " + tempWriteFilePath); tempFile.delete(); } } }
/** * This method will read the local carbon data file and write to carbon data file in HDFS * * @param carbonStoreFilePath * @param localFilePath * @param bufferSize * @param blockSize * @throws IOException */ private static void copyLocalFileToCarbonStore(String carbonStoreFilePath, String localFilePath, int bufferSize, long blockSize) throws IOException { DataOutputStream dataOutputStream = null; DataInputStream dataInputStream = null; try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("HDFS file block size for file: " + carbonStoreFilePath + " is " + blockSize + " (bytes"); } dataOutputStream = FileFactory .getDataOutputStream(carbonStoreFilePath, FileFactory.getFileType(carbonStoreFilePath), bufferSize, blockSize); dataInputStream = FileFactory .getDataInputStream(localFilePath, FileFactory.getFileType(localFilePath), bufferSize); IOUtils.copyBytes(dataInputStream, dataOutputStream, bufferSize); } finally { CarbonUtil.closeStream(dataInputStream); CarbonUtil.closeStream(dataOutputStream); } }