小编kai*_*64b的帖子

如何使用java spark下载文件?

我想为文件下载编写简单的rest api.

我无法找到有关它的文档,因为我知道我需要设置mimetype='application/zip'响应,但不清楚如何返回流.

http://sparkjava.com/

更新:这里解决了示例代码:

public static void main(String[] args) {
    //setPort(8080);
    get("/hello", (request, responce) -> getFile(request,responce));
}

private static Object getFile(Request request, Response responce) {
    File file = new File("MYFILE");
    responce.raw().setContentType("application/octet-stream");
    responce.raw().setHeader("Content-Disposition","attachment; filename="+file.getName()+".zip");
    try {

        try(ZipOutputStream zipOutputStream = new ZipOutputStream(new BufferedOutputStream(responce.raw().getOutputStream()));
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file)))
        {
            ZipEntry zipEntry = new ZipEntry(file.getName());

            zipOutputStream.putNextEntry(zipEntry);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = bufferedInputStream.read(buffer)) > 0) {
                zipOutputStream.write(buffer,0,len);
            }
        }
    } catch (Exception e) {
        halt(405,"server …
Run Code Online (Sandbox Code Playgroud)

java rest spark-java

10
推荐指数
1
解决办法
8596
查看次数

Boost.Asio错误的本地端点

代码示例:

#include "stdafx.h"
#include <boost/asio.hpp>
#include <winsock2.h>
#include <iostream>
#include <string>


int _tmain(int argc, _TCHAR* argv[])
{
    boost::asio::io_service  service;
    auto sock_ = new boost::asio::basic_stream_socket< boost::asio::ip::tcp >(service);
    if(sock_){
        try {
            boost::asio::ip::address_v4 ipa = boost::asio::ip::address_v4::from_string(argv[1]);
            boost::asio::ip::basic_endpoint<  boost::asio::ip::tcp > address(ipa, (unsigned short) atoi(argv[2]));
            sock_->connect(address);
            std::cout<<"connected. local address:"<<sock_->local_endpoint()<<" remote address:"<<sock_->remote_endpoint()<<std::endl;
        } catch (const boost::system::system_error& e)
        {
            std::cout<<"ERROR:"<<e.what();
        }
    }
    int dummy;
    std::cin>>dummy;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我有2台电脑.

  1. 计算机输出A:已连接.本地地址:XXXXXX远程地址:YYYYY(其中XXXXX和YYYY真实IP(IP输出相同的IP))

  2. 计算机B输出:连接.本地地址:127.0.0.1远程地址:YYYYY(其中YYYY为真IP(与ping输出的IP相同))

计算机A和B只有1个NIC
我为什么得到127.0.0.1?我无法从IP 127.0.0.1到YYYY建立真正的连接.
怎么解决?
更新:
甚至Windows套接字在有问题的主机上返回127.0.0.1,请参阅下面的代码

WSADATA wsaData;
auto iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); …
Run Code Online (Sandbox Code Playgroud)

c++ boost network-programming boost-asio

10
推荐指数
1
解决办法
914
查看次数

"CodeTaskFactory加载"上的VS 2015 C++编译失败

我有一个奇怪的错误:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(219,5): error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.Core.dll". Timed out waiting for a program to execute. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"E:\BuildAgent\temp\buildTmp\dxr3ks1s.cmdline".
Run Code Online (Sandbox Code Playgroud)

我禁用了代码分析:

<RunCodeAnalysis>false</RunCodeAnalysis>
<RunCodeAnalysisOnThisProject>false</RunCodeAnalysisOnThisProject>
Run Code Online (Sandbox Code Playgroud)

但我看到同样的错误:(

c++ compilation visual-c++ visual-studio-2015 devops

6
推荐指数
1
解决办法
431
查看次数

传递给 LogonUser() 的密码不正确,但 Active Directory 帐户未按预期锁定

我有活动目录“登录重试次数”= 3。我们使用错误的密码调用了 LogonUser函数 5 次。之后我LogonUser用正确的密码打电话,它可以工作,用户可以登录。

为什么账户没有被锁定?

c++ winapi active-directory

5
推荐指数
1
解决办法
1773
查看次数

WIX 合并 C++ 运行时

我已经合并了 msm 与 2015 crt:

<DirectoryRef Id="TARGETDIR" >
<Merge Id = "Microsoft_VC140_CRT_x64.msm" FileCompression = "yes" Language = "1033" SourceFile = "..\\..\\..\\..\\..\\..\\..\\external\\tools\\systemsetups\\merge_modules\\Microsoft_VC140_CRT_x64.msm" DiskId = "1" />"
</DirectoryRef>
<Feature>
<Feature Id="Complete" Title="Complete" Absent="allow" Level="1">
...
<MergeRef Id="Microsoft_VC140_CRT_x64.msm"/>
...
</Feature> 
Run Code Online (Sandbox Code Playgroud)

但我仍然收到:

---------------------------
MyApp.exe - System Error
---------------------------
The program can't start because mfc140u.dll is missing from your computer. Try reinstalling the program to fix this problem. 
---------------------------
OK   
---------------------------
Run Code Online (Sandbox Code Playgroud)

有什么想法如何正确合并它吗?

windows-installer wix visual-c++-runtime

3
推荐指数
1
解决办法
1827
查看次数