/// <exception cref="System.IO.IOException"/> public virtual void WriteToFile(Path loc, JobConf job, Checksum crc) { FileSystem rfs = FileSystem.GetLocal(job).GetRaw(); CheckedOutputStream chk = null; FSDataOutputStream @out = rfs.Create(loc); try { if (crc != null) { crc.Reset(); chk = new CheckedOutputStream(@out, crc); chk.Write(((byte[])buf.Array())); @out.WriteLong(chk.GetChecksum().GetValue()); } else { @out.Write(((byte[])buf.Array())); } } finally { if (chk != null) { chk.Close(); } else { @out.Close(); } } }
/// <exception cref="System.IO.IOException"/> private static void WriteFile(FileSystem fs, Path f, long fill, int parts) { FSDataOutputStream @out = fs.Create(f, false); CheckedOutputStream iout = new CheckedOutputStream(@out, new CRC32()); DataOutputStream dout = new DataOutputStream(iout); for (int i = 0; i < parts; ++i) { for (int j = 0; j < MapTask.MapOutputIndexRecordLength / 8; ++j) { dout.WriteLong(fill); } } @out.WriteLong(iout.GetChecksum().GetValue()); dout.Close(); }
/// <exception cref="System.Exception"/> public virtual void TestBadIndex() { int parts = 30; fs.Delete(p, true); conf.SetInt(TTConfig.TtIndexCache, 1); IndexCache cache = new IndexCache(conf); Path f = new Path(p, "badindex"); FSDataOutputStream @out = fs.Create(f, false); CheckedOutputStream iout = new CheckedOutputStream(@out, new CRC32()); DataOutputStream dout = new DataOutputStream(iout); for (int i = 0; i < parts; ++i) { for (int j = 0; j < MapTask.MapOutputIndexRecordLength / 8; ++j) { if (0 == (i % 3)) { dout.WriteLong(i); } else { @out.WriteLong(i); } } } @out.WriteLong(iout.GetChecksum().GetValue()); dout.Close(); try { cache.GetIndexInformation("badindex", 7, f, UserGroupInformation.GetCurrentUser() .GetShortUserName()); Fail("Did not detect bad checksum"); } catch (IOException e) { if (!(e.InnerException is ChecksumException)) { throw; } } }
public RawOutput(Stream stream) { this._checkedStream = new CheckedOutputStream(stream, new Adler32()); this.writer = new BinaryWriter(this._checkedStream); }