/// <exception cref="System.IO.IOException"/> private void FillOutput(InMemoryMapOutput <Text, Text> output) { BoundedByteArrayOutputStream stream = output.GetArrayStream(); int count = stream.GetLimit(); for (int i = 0; i < count; ++i) { stream.Write(i); } }
/// <exception cref="System.IO.IOException"/> public virtual void TestBoundedStream() { BoundedByteArrayOutputStream stream = new BoundedByteArrayOutputStream(Size); // Write to the stream, get the data back and check for contents stream.Write(Input, 0, Size); Assert.True("Array Contents Mismatch", Arrays.Equals(Input, stream .GetBuffer())); // Try writing beyond end of buffer. Should throw an exception bool caughtException = false; try { stream.Write(Input[0]); } catch (Exception) { caughtException = true; } Assert.True("Writing beyond limit did not throw an exception", caughtException); //Reset the stream and try, should succeed stream.Reset(); Assert.True("Limit did not get reset correctly", (stream.GetLimit () == Size)); stream.Write(Input, 0, Size); Assert.True("Array Contents Mismatch", Arrays.Equals(Input, stream .GetBuffer())); // Try writing one more byte, should fail caughtException = false; try { stream.Write(Input[0]); } catch (Exception) { caughtException = true; } // Reset the stream, but set a lower limit. Writing beyond // the limit should throw an exception stream.Reset(Size - 1); Assert.True("Limit did not get reset correctly", (stream.GetLimit () == Size - 1)); caughtException = false; try { stream.Write(Input, 0, Size); } catch (Exception) { caughtException = true; } Assert.True("Writing beyond limit did not throw an exception", caughtException); }
public InMemoryMapOutput(Configuration conf, TaskAttemptID mapId, MergeManagerImpl <K, V> merger, int size, CompressionCodec codec, bool primaryMapOutput) : base(mapId, (long)size, primaryMapOutput) { // Decompression of map-outputs this.conf = conf; this.merger = merger; this.codec = codec; byteStream = new BoundedByteArrayOutputStream(size); memory = byteStream.GetBuffer(); if (codec != null) { decompressor = CodecPool.GetDecompressor(codec); } else { decompressor = null; } }
public InMemoryWriter(BoundedByteArrayOutputStream arrayStream) : base(null) { this.@out = new DataOutputStream(new IFileOutputStream(arrayStream)); }