internal BContentStream createStreamRequest(Stream strm) { if (streams == null) { streams = new List <BContentStream>(); } BContentStream bstrm = null; if (strm is BContentStream) { bstrm = (BContentStream)strm; } else { bstrm = new BContentStreamWrapper(strm); } // If the stream has already a streamId, it has been received // from the server. In this case, the application obviously // wants to forward the stream to another client. Thus // we do not have to upload the stream. if (bstrm.TargetId.isZero()) { BTargetId targetId = new BTargetId( transport.getConnectedServerId(), header.messageId, transport.getWire().makeMessageId()); bstrm.TargetId = targetId; streams.Add(bstrm); } return(bstrm); }
public virtual void copyProperties(BContentStream rhs) { contentTypeVal = rhs.ContentType; contentLengthVal = rhs.ContentLength; fileNameVal = rhs.FileName; attachmentCodeVal = rhs.AttachmentCode; targetIdVal = rhs.TargetId; }
void internalPutStream(RequestToCancel request) { long messageId = request.messageId; long streamId = request.streamId; Stream stream = request.stream; if (log.isDebugEnabled()) { log.debug("internalPutStream(messageId=" + messageId + ", streamId=" + streamId + ", stream=" + stream); } String contentType = null; long contentLength = -1L; String contentDisposition = null; if (stream is BContentStream) { BContentStream cstream = (BContentStream)stream; contentType = cstream.ContentType; contentLength = cstream.ContentLength; contentDisposition = cstream.ContentDisposition; } HttpWebRequest conn = (HttpWebRequest)HttpWebRequest.Create(url + "?messageid=" + messageId + "&streamid=" + streamId); request.setConnection(conn); conn.AllowWriteStreamBuffering = false; conn.Method = "PUT"; conn.SendChunked = (contentLength == -1L); if (contentLength != -1L) { conn.ContentLength = contentLength; } conn.ContentType = contentType != null ? contentType : HConstants.DEFAULT_CONTENT_TYPE; if (contentDisposition != null) { conn.Headers.Add("Content-Disposition", contentDisposition); } applySession(conn); conn.BeginGetRequestStream(new AsyncCallback(this.getRequestStreamCallback), request); if (log.isDebugEnabled()) { log.debug(")internalPutStream"); } }
public RequestToCancel createRequestForPutStream(BContentStream stream, BAsyncResultIF <BMessage> asyncResult) { RequestToCancel r = new RequestToCancel(this, ERequestDirection.FORWARD, stream.TargetId.getMessageId(), null, stream, stream.TargetId.getStreamId(), 0L, timeoutMillisClient, timeoutMillisClient, asyncResult); addRequest(r); return(r); }
public override Object read(Object obj, BInput bin1, long version) { BInputBin bin = ((BInputBin)bin1); BTargetId targetId = null; long contentLength = -1; String contentType = BContentStream.DEFAULT_CONTENT_TYPE; int attachmentCode = 0; String fileName = ""; bool withProps = bin1.header.bversion >= BMessageHeader.BYPS_VERSION_EXTENDED_STREAM_INFORMATION; if (withProps) { targetId = BTargetId.read(bin.bbuf.getBuffer(), bin1.header.bversion); contentLength = bin.bbuf.getLong(); contentType = bin.bbuf.getString(); attachmentCode = bin.bbuf.getInt(); fileName = bin.bbuf.getString(); } else { long streamId = bin.bbuf.getLong(); int serverId = bin1.transport.getTargetId().getServerId(); long messageId = bin1.header.messageId; targetId = new BTargetId(serverId, messageId, streamId); } try { BContentStream strm = bin.transport.getWire().getStream(targetId); bin.onObjectCreated(strm); strm.ContentLength = contentLength; strm.ContentType = contentType; strm.AttachmentCode = attachmentCode; strm.FileName = fileName; return(strm); } catch (IOException e) { throw new BException(BExceptionC.IOERROR, e.Message); } }
public override void write(Object obj, BOutput bout1, long version) { BOutputBin bout = ((BOutputBin)bout1); Stream strm = (Stream)obj; BContentStream bstream = bout.createStreamRequest(strm); BTargetId targetId = bstream.TargetId; bool withProps = bout1.header.bversion >= BMessageHeader.BYPS_VERSION_EXTENDED_STREAM_INFORMATION; if (withProps) { bstream.TargetId.write(bout.bbuf.getBuffer(), bout1.header.bversion); bout.bbuf.putLong(bstream.ContentLength); bout.bbuf.putString(bstream.ContentType); bout.bbuf.putInt(bstream.AttachmentCode); bout.bbuf.putString(bstream.FileName); } else { bout.bbuf.putLong(targetId.getStreamId()); } }
protected Stream ensureStream() { if (innerStream != null) { return(innerStream); } lock (this) { if (innerStream == null) { innerStream = openStream(); if (innerStream is BContentStream) { BContentStream bstrm = (BContentStream)innerStream; this.copyProperties(bstrm); } } } return(innerStream); }
public RequestToCancel(HWireClient wire, ERequestDirection requestDirection, long messageId, ByteBuffer buf, BContentStream stream, long streamId, long cancelMessageId, int timeoutMillisClient, int timeoutMillisRequest, BAsyncResultIF <BMessage> asyncResult) { this.wire = wire; this.requestDirection = requestDirection; this.messageId = messageId; this.streamId = streamId; this.buf = buf; this.stream = stream; this.cancelMessageId = cancelMessageId; this.timeoutMillisClient = timeoutMillisClient; this.timeoutMillisRequest = timeoutMillisRequest; this.asyncResult = asyncResult; this.id = Interlocked.Increment(ref requestCounter); }
public BContentStreamWrapper(BContentStream innerStream, long reserved) : base(innerStream, 0) { this.innerStream = innerStream; }
public BContentStream(BContentStream rhs, long lifetimeMillis) { copyProperties(rhs); }