clamav-rest Spring 3.2 RestTemplate results in 400 Bad Request

I’m trying to send a file to a Spring Boot application clamav-rest. The curl command is working fine. Here’s the output,

curl -k -F name="test file" -F file=@"myfile.pdf" https://clamav.my.org/scan
POST /scan HTTP/1.1
Host: clamav.my.org
User-Agent: curl/7.56.1
Accept: */*
Content-Length: 22834
Content-Type: multipart/form-data; boundary=------------------------5814453ea3a5f3e0
Expect: 100-continue
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Thu, 18 Jan 2018 23:19:10 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 21
Everything ok : true

I’m using Spring 3.2 to make a REST call, which results in a 400 Bad Request error.

MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.add("name", "fileUpload.obj");
parts.add("file", in);

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);

HttpEntity<MultiValueMap<String, Object>> requestEntity = 
    new HttpEntity<MultiValueMap<String, Object>>(parts, headers);

ResponseEntity<String> responseEntity = 
    restTemplate.exchange("https://clamav.my.org/scan", HttpMethod.POST, requestEntity, String.class);
String body = (String) responseEntity.getBody();

Here’s the log output

Created POST request for "https://clamav.nccourts.org/scan"
Setting request Accept header to [text/plain, application/json, application/*+json, */*]
Writing [{name=[fileUpload.obj], file=[[B@fe97ef91]}] as "multipart/form-data" using [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@4885d075]
POST request for "https://clamav.my.org/scan" resulted in 400 (Bad Request); invoking error handler
Created POST request for "https://clamav.my.org/scan"
Setting request Accept header to [text/plain, application/json, application/*+json, */*]
Writing [{file=[[B@fe97ef91]}] using [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@e8e8b3fa]
POST request for "https://clamav.my.org/scan" resulted in 400 (Bad Request); invoking error handler

I’ve tried several iterations and searched all over for example code. Any thoughts about how to make a successful request? TIA

How do I take a + symbol from an arraylist and put it into a equation?

I want to create a program that when you put an expression of unknown length, ?

using only addition subtraction multiplication and division, evaluates the expression and comes back with an answer.

package math;
import java.util.ArrayList;
import java.util.Scanner;

class Numberthing{

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void main(String args[]) {
        String expression;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter a string");

        expression = input.nextLine();

        System.out.println("You entered string "+expression);

        System.out.println("The length of the expression is "+expression.length());

        ArrayList<String> expressionList=new ArrayList<String>();

        for (int iterator = 0; iterator <= expression.length(); iterator++) {
            System.out.println(expression.charAt(iterator));
            String temporarystring = String.valueOf(expression.charAt(iterator));
            expressionList.add(

now that it is in the string, how do I turn it into an equation.

for (int iterator = 0; iterator <=  expression.length(); iterator++) {

    }



  }
}

Swiping Down crashes app

So I’m using the library Swipe by Pwittchen and the code being used is this section:

CoreActivity.java

 @Override
        public void onSwipedDown(final MotionEvent event) {

            if(m_Toolbar.getVisibility() == View.VISIBLE ){
                WebShrink.cancel();
            }
            //WebView Animation (Shrink)
           // if(m_WebView.getAnimation().hasStarted() || m_WebView.getAnimation().hasEnded()){
            if(WebEnlarge.hasStarted()){
                WebShrink = AnimationUtils.loadAnimation(CoreActivity.this,R.anim.m_webview_shrink);
                m_WebView.startAnimation(WebShrink);
                m_Preference_Toolbar.setVisibility(View.GONE);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        m_Toolbar.setVisibility(View.VISIBLE);
                    }
                }, 350);//3 seconds
            }
        }

Currently I crashes if you swipe down in the moment it is created. Im trying to find a way around it with:

 if(m_Toolbar.getVisibility() == View.VISIBLE ){
            WebShrink.cancel();
        }

but this is not working and am wondering if anyone could help me with this. the ideal situation is that if the toolbar is visible or if WebShrink is already in place then do nothing but I can’t find away around it

LogCat

 01-18 20:57:23.652 29764-29764/com.equiware.mickeyt.fire    E/InputEventReceiver: Exception dispatching input event.
01-18 20:57:23.653 29764-29764/com.equiware.mickeyt.fire D/AndroidRuntime: Shutting down VM
01-18 20:57:23.654 29764-29764/com.equiware.mickeyt.fire E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.equiware.mickeyt.fire, PID: 29764
                                                                        java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.cancel()' on a null object reference
                                                                           at com.equiware.mickeyt.fire.CoreActivity$2.onSwipedDown(CoreActivity.java:161)
                                                                           at com.github.pwittchen.swipe.library.rx2.Swipe.onActionUp(Swipe.java:138)
                                                                             at  com.github.pwittchen.swipe.library.rx2.Swipe.dispatchTouchEvent(Swipe.java:101)
                                                                           at com.equiware.mickeyt.fire.CoreActivity.dispatchTouchEvent(CoreActivity.java:216)
                                                                           at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
                                                                           at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:374)
                                                                           at android.view.View.dispatchPointerEvent(View.java:10177)
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4628)
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4496)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4095)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4152)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4000)
                                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3966)
                                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3974)
                                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3947)
                                                                           at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6437)
                                                                           at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6411)
                                                                           at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6372)
                                                                           at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6571)
                                                                           at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                           at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                           at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
                                                                           at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6519)
                                                                           at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6594)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:683)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:613)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
                                                                           at android.os.Handler.handleCallback(Handler.java:751)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6247)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at   com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

My notification won’t repeat

I’m trying to create a notification that repeats every interval (eg 15 mins), I’m using an alarm manager and a notify service.

here’s the section where I start the alarm:

private void alarmMethod(){
        Intent myIntent = new Intent(this , NotifyService.class);
        AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
        pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

        Calendar calendar = Calendar.getInstance();
        Calendar currentCal = Calendar.getInstance();


        calendar.set(Calendar.SECOND, currentCal.get(Calendar.SECOND));
        calendar.set(Calendar.MINUTE, currentCal.get(Calendar.MINUTE) + 1);
        calendar.set(Calendar.HOUR, currentCal.get(Calendar.HOUR));
        calendar.set(Calendar.AM_PM, currentCal.get(Calendar.AM_PM));

        long intendedTime = calendar.getTimeInMillis();
        long currentTime = currentCal.getTimeInMillis();

        if(intendedTime >= currentTime){
            // you can add buffer time too here to ignore some small differences in milliseconds
            // set from today
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
                    AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);

        } else{
            // set from next day
            // you might consider using calendar.add() for adding one day to the current day
            //calendar.add(Calendar.DAY_OF_MONTH, 1);
            intendedTime = calendar.getTimeInMillis();
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
                    AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
        }
        Toast.makeText(LoginActivity.this, "Starting Alarm", Toast.LENGTH_LONG).show();

        /*
        if (alarmManager != null) {
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, pendingIntent);
        }*/

    }

Heres the notify service:

public class NotifyService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onCreate(){
        Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Intent intent1 = new Intent(this.getApplicationContext(), LoginActivity.class);

        intent1.putExtra("receivedTokens", true);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent1, 0);

        Notification.Builder mNotify = new Notification.Builder(this)
                .setContentTitle("Token bonus!")
                .setContentText("You can now receive your daily token bonus!")
                .setSmallIcon(R.drawable.event)
                .setContentIntent(pIntent)
                .setSound(sound)
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL)
                //.addAction(0, "Login now", pIntent)
                .setAutoCancel(true);
        //int flags = Notification.FLAG_AUTO_CANCEL;
        //mNotify.build().flags = flags;
        if (mNM != null) {
            mNM.notify(1,mNotify.build());
        }

    }
}

And for when the device reboot here’s the device reboot receiver:

public class DeviceBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            /* Setting the alarm here */
            Intent alarmIntent = new Intent(context, NotifyService.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

            AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            int interval = (int) AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

            Toast.makeText(context, "Starting Alarm...", Toast.LENGTH_SHORT).show();
        }
    }
}

and here a section of the android manifest file:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>



        <!-- Will not be called unless the application explicitly enables it -->
        <receiver android:name=".DeviceBootReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

(Java) To replace with a slash, why are 4 slashes required in replacement argument of String’s replaceAll method? [duplicate]

This question already has an answer here:

In Java, the string "\" represents a single backlash, the first backslash being an escape character. Thus System.out.print("\") prints . However if "\" is given as the replacement argument in method replaceAll, as in "aba".replaceAll("b", "\"), the following exception is thrown: java.lang.IllegalArgumentException: character to be escaped is missing.

Four slashes does the trick. Thus if one prints "aba".replaceAll("b", "\\") the result is aa. But why is two slashes incorrect? Isn’t the first slash the escaping slash, and the second slash the character to be escaped, just like in System.out.print("\")? Notice that only one escaping slash is sufficient for other replacement strings passed to replaceAll. E.g. printing "aba".replaceAll("b", "t") results in a a.

Note: I’m using Java SE 9.

Regex vs Using Array

Lets say I have to find if a String contains a number or not. I know two ways to do it (of course, some may know more than 2):

Using Regex:

public static void main(String[] args) {
    String name = "name2";
    Pattern pattern = Pattern.compile("(.*)(\d)(.*)");
    Matcher matcher = pattern.matcher(name);
    System.out.println(matcher.matches());
}

Using Array:

public static void main(String[] args) {
    String name = "name1";
    boolean numberFound = false;
    char[] characters = name.toCharArray();
    for (char eachChar : characters) {
        int ascii = (int)eachChar;
        if (ascii >= 48 && ascii <= 57) {
            numberFound = true;
            break;
        }
    }
    System.out.println(numberFound);
}

Which option will be faster and why?

Get serverTime from firebase in grenwich time

Im using this method to get the time from the firebase server, but if a user have another TimeServer in their phone it cause troubles in my app. Anybody knows how can i do this works getting GreenWich meridian, or get in any country in the world the current time from the server in EUA, i know when user System.currentMilis() this take the Time from the cellphone. But how i can get the value from the double offset.

DatabaseReference offsetRef = FirebaseDatabase.getInstance().getReference(".info/serverTimeOffset");
offsetRef.addValueEventListener(new ValueEventListener() {


 @Override
  public void onDataChange(DataSnapshot snapshot) {
    double offset = snapshot.getValue(Double.class);
    double estimatedServerTimeMs = System.currentTimeMillis() + offset;
  }

  @Override
  public void onCancelled(DatabaseError error) {
    System.err.println("Listener was cancelled");
  }
});

How to access & manipulate my MySQL table remotely

I’ve made a Mysql db that i can easily manipulate with java,

However I cant access it from other machines since its running off localhost only right? How would i go about making it so i would be able to manipulate the data from another machine. Or am i going about this all wrong? I’ve tried playing around with the remote access on MySQL workbench but i’m just not understanding it.

Here is how i’m accessing it currently.

 Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sampledatabase");

SSL error on HTTP GET

I am getting

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Things i have tried:
1. Adding cert to my keystore
2. Using a custom TrustModifier to not validate. This cause the SSL error to change to http 401 error

Here is my code

URL website = new URL(urlpath);
        HttpURLConnection conn = (HttpURLConnection) website.openConnection();
        conn.setRequestMethod("GET");

        //TrustModifier.relaxHostChecking(conn);
        InputStream is = conn.getInputStream();
        FileOutputStream out = new FileOutputStream(path);
        copyStream (is, out);
        out.close();