mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
fixed UploaderFactoryTest
This commit is contained in:
@ -6,23 +6,30 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
|||||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||||
import processing.app.Preferences;
|
|
||||||
import processing.app.SerialException;
|
import processing.app.SerialException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
public class HttpUploader extends Uploader {
|
public class HttpUploader extends Uploader {
|
||||||
|
|
||||||
|
private static final Pattern IPV4_ADDRESS = Pattern.compile("(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})");
|
||||||
|
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
private final String ipAddress;
|
private final String ipAddress;
|
||||||
|
|
||||||
public HttpUploader() {
|
public HttpUploader(String port) {
|
||||||
this.client = new HttpClient();
|
this.client = new HttpClient();
|
||||||
this.ipAddress = Preferences.get("serial.port").substring(0, Preferences.get("serial.port").indexOf(" "));
|
Matcher matcher = IPV4_ADDRESS.matcher(port);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
throw new IllegalArgumentException(port);
|
||||||
|
}
|
||||||
|
this.ipAddress = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,7 @@ public class UploaderFactory {
|
|||||||
|
|
||||||
public Uploader newUploader(Map<String, String> preferences, String port) {
|
public Uploader newUploader(Map<String, String> preferences, String port) {
|
||||||
if ("true".equals(preferences.get("upload.via_http")) && IPV4_ADDRESS.matcher(port).find()) {
|
if ("true".equals(preferences.get("upload.via_http")) && IPV4_ADDRESS.matcher(port).find()) {
|
||||||
return new HttpUploader();
|
return new HttpUploader(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BasicUploader();
|
return new BasicUploader();
|
||||||
|
Reference in New Issue
Block a user