我应该从 3rd party API 下载 ZIP 文件。但是,当我使用 Spring Webclient 时,我最终得到一个空文件。有什么想法我做错了吗?将内容存储Flux<DataBuffer>
到文件的正确方法是什么?
这是我的代码:
WebClient client = WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient1))
.baseUrl(String.format(FILE_DOWNLOAD_PATH))
.build();
WebClient.RequestBodyUriSpec method = client.method(HttpMethod.GET);
method.header("Authorization", "Bearer " + accessToken);
final Flux<DataBuffer> dataBufferFlux = method.retrieve().bodyToFlux(DataBuffer.class);
final Path path = FileSystems.getDefault().getPath("example" + new Random(200).nextInt() + ".zip");
WritableByteChannel channel = Files.newByteChannel(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
Mono<Path> then = DataBufferUtils.write(dataBufferFlux, channel)
.map(DataBufferUtils::release)
.then(Mono.just(path));
Run Code Online (Sandbox Code Playgroud)
更新:上面的代码直接从 main 调用,然后应用程序关闭。这会是一个问题吗?
正如标题所说:如何向使用 JFreeChart 创建的烛台图表添加水平滚动条?我希望用户能够在放大时水平滚动图表。现在放大有效,但我无法向左或向右移动。我尝试将 ChartPanel 放入 JScrollPane 中,但那是一个图表面板,而不是图表本身。我的自定义 ChartPanel 构造函数:
public MyChartPanel(JFreeChart chart) {
super(chart);
lineDrawingControllers =new EventListenerList();
this.setMouseZoomable(false);
this.addMouseListener(mouseHandler);
this.addMouseMotionListener(mouseHandler);
this.setPopupMenu(null);
this.linePopupMenu=new JPopupMenu();
linePopupMenuListener=new LinePopupMenuListener();
}
Run Code Online (Sandbox Code Playgroud)
我的自定义 Jpanel 在其中创建 Chart 和 ChartPanel 并将 ChartPanel 放在 JScrollPane 中:
public MyCandleStickChart() {
ohlcSeries = new OHLCSeries("Test data");
ohlcSeriesCollection = new OHLCSeriesCollection();
ohlcSeriesCollection.addSeries(ohlcSeries);
ohlcSeries=ohlcSeriesCollection.getSeries(0);
chart= ChartFactory.createCandlestickChart("Default Chart", "Time", "Value", ohlcSeriesCollection, true);
chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
chartPanel=new MyChartPanel(chart);
chartPanel.setDisplayToolTips(false);
jScrollPane=new JScrollPane(chartPanel);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
add(jScrollPane);
add(tooltipPanel);
}
Run Code Online (Sandbox Code Playgroud)
然后我将 MyCandleStickChart JPanel 添加到主应用程序框架:
myCandleStickChart=new MyCandleStickChart();
applicationFrame.add(myCandleStickChart, BorderLayout.CENTER);
Run Code Online (Sandbox Code Playgroud)