/// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Namenode.SaveNamespaceCancelledException /// "/> public virtual void CheckCancelled() { if (canceller.IsCancelled()) { throw new SaveNamespaceCancelledException(canceller.GetCancellationReason()); } }
/// <exception cref="System.IO.IOException"/> private static void CopyFileToStream(OutputStream @out, FilePath localfile, FileInputStream infile, DataTransferThrottler throttler, Canceler canceler) { byte[] buf = new byte[HdfsConstants.IoFileBufferSize]; try { CheckpointFaultInjector.GetInstance().AboutToSendFile(localfile); if (CheckpointFaultInjector.GetInstance().ShouldSendShortFile(localfile)) { // Test sending image shorter than localfile long len = localfile.Length(); buf = new byte[(int)Math.Min(len / 2, HdfsConstants.IoFileBufferSize)]; // This will read at most half of the image // and the rest of the image will be sent over the wire infile.Read(buf); } int num = 1; while (num > 0) { if (canceler != null && canceler.IsCancelled()) { throw new SaveNamespaceCancelledException(canceler.GetCancellationReason()); } num = infile.Read(buf); if (num <= 0) { break; } if (CheckpointFaultInjector.GetInstance().ShouldCorruptAByte(localfile)) { // Simulate a corrupted byte on the wire Log.Warn("SIMULATING A CORRUPT BYTE IN IMAGE TRANSFER!"); buf[0]++; } @out.Write(buf, 0, num); if (throttler != null) { throttler.Throttle(num, canceler); } } } catch (EofException) { Log.Info("Connection closed by client"); @out = null; } finally { // so we don't close in the finally if (@out != null) { @out.Close(); } } }