Java Code Examples for reactor.core.publisher.SynchronousSink#complete()

The following examples show how to use reactor.core.publisher.SynchronousSink#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataBufferUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void accept(SynchronousSink<DataBuffer> sink) {
	boolean release = true;
	DataBuffer dataBuffer = this.dataBufferFactory.allocateBuffer(this.bufferSize);
	try {
		int read;
		ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, dataBuffer.capacity());
		if ((read = this.channel.read(byteBuffer)) >= 0) {
			dataBuffer.writePosition(read);
			release = false;
			sink.next(dataBuffer);
		}
		else {
			sink.complete();
		}
	}
	catch (IOException ex) {
		sink.error(ex);
	}
	finally {
		if (release) {
			release(dataBuffer);
		}
	}
}
 
Example 2
Source File: DataBufferUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void accept(SynchronousSink<DataBuffer> sink) {
	boolean release = true;
	DataBuffer dataBuffer = this.dataBufferFactory.allocateBuffer(this.bufferSize);
	try {
		int read;
		ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, dataBuffer.capacity());
		if ((read = this.channel.read(byteBuffer)) >= 0) {
			dataBuffer.writePosition(read);
			release = false;
			sink.next(dataBuffer);
		}
		else {
			sink.complete();
		}
	}
	catch (IOException ex) {
		sink.error(ex);
	}
	finally {
		if (release) {
			release(dataBuffer);
		}
	}
}
 
Example 3
Source File: Files.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
public FileState consumeNext(SynchronousSink<ByteBuf> sink) {
  if (inputStream == null) {
    InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
    if (in == null) {
      sink.error(new FileNotFoundException(fileName));
      return this;
    }
    this.inputStream = new BufferedInputStream(in);
    this.chunkBytes = new byte[chunkSizeBytes];
  }
  try {
    int consumedBytes = inputStream.read(chunkBytes);
    if (consumedBytes == -1) {
      sink.complete();
    } else {
      sink.next(Unpooled.copiedBuffer(chunkBytes, 0, consumedBytes));
    }
  } catch (IOException e) {
    sink.error(e);
  }
  return this;
}
 
Example 4
Source File: AppCacheManifestTransformer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void accept(SynchronousSink<LineInfo> sink) {
	if (this.scanner.hasNext()) {
		String line = this.scanner.nextLine();
		LineInfo current = new LineInfo(line, this.previous);
		sink.next(current);
		this.previous = current;
	}
	else {
		sink.complete();
	}
}
 
Example 5
Source File: AppCacheManifestTransformer.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void accept(SynchronousSink<LineInfo> sink) {
	if (this.scanner.hasNext()) {
		String line = this.scanner.nextLine();
		LineInfo current = new LineInfo(line, this.previous);
		sink.next(current);
		this.previous = current;
	}
	else {
		sink.complete();
	}
}