public HdfsLogAppendStream(Uri logUri, bool deleteIfExists) { _logUri = logUri; string logPath = _logUri.AbsolutePath; string logDirectory = logPath.Substring(0, logPath.LastIndexOf('/')); _writePosition = 0; try { _hdfs = new HdfsInstance(_logUri); _hdfs.EnsureDirectory(logDirectory); if (_hdfs.IsFileExists(logPath)) { if (deleteIfExists) { _hdfs.DeleteFile(logPath, false); } else { throw new ApplicationException("Log file " + logUri.AbsoluteUri + " already exists"); } } _writer = _hdfs.OpenCreate(logPath, 1024 * 1024, -1); } catch (Exception e) { throw new ApplicationException("HdfsLogAppendStream failed to open writer", e); } }
public override void Close() { if (writer != null) { writer.Dispose(); writer = null; } }
public HdfsStreamWriter(HdfsInstance instance, string dfsPath, string user, int bufferSize, long blockSize) { this.writer = instance.OpenCreate(dfsPath, bufferSize, blockSize); instance.SetOwnerAndPermission(dfsPath, user, null, Convert.ToInt16("644", 8)); }