All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threatconnect.sdk.client.reader.ExchangeReaderAdapter Maven / Gradle / Ivy

Go to download

The ThreatConnect Java SDK. Used to communicate with teh ThreatConnect Threat Intelligence Platform

The newest version!
package com.threatconnect.sdk.client.reader;

import com.threatconnect.sdk.conn.Connection;
import com.threatconnect.sdk.exception.FailedResponseException;
import com.threatconnect.sdk.server.entity.SpaceState;
import com.threatconnect.sdk.server.response.entity.SpaceStateResponse;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by dtineo on 9/12/15.
 */
public class ExchangeReaderAdapter extends AbstractReaderAdapter
{

    public ExchangeReaderAdapter(Connection conn)
    {
        super(conn);
    }

    public void downloadSpacesFile(int spaceId, String fileName, Path outputPath) throws FailedResponseException
    {
        Map paramMap = new HashMap<>();
        paramMap.put("id", spaceId);
        paramMap.put("fileName", fileName);
        try (InputStream in = getFile("v2.spaces.file", /*owner=*/null, paramMap, /*bypassOwnerCheck=*/true))
        {
            Files.copy(in, outputPath, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e)
        {
            e.printStackTrace();
            throw new FailedResponseException("Failed to download file");
        }
    }

    public SpaceState getSpaceState(int spaceId) throws IOException, FailedResponseException {
        Map paramMap = new HashMap<>();
        paramMap.put("id", spaceId);

        SpaceStateResponse data = getItem("v2.spaces.state", SpaceStateResponse.class, /*owner=*/null, paramMap, /*bypassOwnerCheck=*/true);

        return (SpaceState) data.getData().getData();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy