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"
POST /scan HTTP/1.1
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();

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

ResponseEntity<String> responseEntity ="", HttpMethod.POST, requestEntity, String.class);
String body = (String) responseEntity.getBody();

Here’s the log output

Created POST request for ""
Setting request Accept header to [text/plain, application/json, application/*+json, */*]
Writing [{name=[fileUpload.obj], file=[[B@fe97ef91]}] as "multipart/form-data" using []
POST request for "" resulted in 400 (Bad Request); invoking error handler
Created POST request for ""
Setting request Accept header to [text/plain, application/json, application/*+json, */*]
Writing [{file=[[B@fe97ef91]}] using []
POST request for "" 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.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++) {
            String temporarystring = String.valueOf(expression.charAt(iterator));

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:

        public void onSwipedDown(final MotionEvent event) {

            if(m_Toolbar.getVisibility() == View.VISIBLE ){
            //WebView Animation (Shrink)
           // if(m_WebView.getAnimation().hasStarted() || m_WebView.getAnimation().hasEnded()){
                WebShrink = AnimationUtils.loadAnimation(CoreActivity.this,R.anim.m_webview_shrink);
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                }, 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 ){

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


 01-18 20:57:23.652 29764-29764/    E/InputEventReceiver: Exception dispatching input event.
01-18 20:57:23.653 29764-29764/ D/AndroidRuntime: Shutting down VM
01-18 20:57:23.654 29764-29764/ E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process:, PID: 29764
                                                                        java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.cancel()' on a null object reference
                                                                           at com.github.pwittchen.swipe.library.rx2.Swipe.onActionUp(
                                                                             at  com.github.pwittchen.swipe.library.rx2.Swipe.dispatchTouchEvent(
                                                                           at android.view.View.dispatchPointerEvent(
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(
                                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(
                                                                           at android.view.ViewRootImpl$InputStage.deliver(
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(
                                                                           at android.view.ViewRootImpl$InputStage.forward(
                                                                           at android.view.ViewRootImpl$InputStage.apply(
                                                                           at android.view.ViewRootImpl$InputStage.deliver(
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(
                                                                           at android.view.ViewRootImpl$InputStage.forward(
                                                                           at android.view.ViewRootImpl$AsyncInputStage.forward(
                                                                           at android.view.ViewRootImpl$InputStage.apply(
                                                                           at android.view.ViewRootImpl$AsyncInputStage.apply(
                                                                           at android.view.ViewRootImpl$InputStage.deliver(
                                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(
                                                                           at android.view.ViewRootImpl$InputStage.forward(
                                                                           at android.view.ViewRootImpl$InputStage.apply(
                                                                           at android.view.ViewRootImpl$InputStage.deliver(
                                                                           at android.view.ViewRootImpl.deliverInputEvent(
                                                                           at android.view.ViewRootImpl.doProcessInputEvents(
                                                                           at android.view.ViewRootImpl.enqueueInputEvent(
                                                                           at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(
                                                                           at android.view.InputEventReceiver.dispatchInputEvent(
                                                                           at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                           at android.view.InputEventReceiver.consumeBatchedInputEvents(
                                                                           at android.view.ViewRootImpl.doConsumeBatchedInput(
                                                                           at android.view.ViewRootImpl$
                                                                           at android.view.Choreographer$
                                                                           at android.view.Choreographer.doCallbacks(
                                                                           at android.view.Choreographer.doFrame(
                                                                           at android.view.Choreographer$
                                                                           at android.os.Handler.handleCallback(
                                                                           at android.os.Handler.dispatchMessage(
                                                                           at android.os.Looper.loop(
                                                                           at java.lang.reflect.Method.invoke(Native Method)

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 {
    public IBinder onBind(Intent intent) {
        return null;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    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!")
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL)
                //.addAction(0, "Login now", pIntent)
        //int flags = Notification.FLAG_AUTO_CANCEL;
        // = flags;
        if (mNM != null) {


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

public class DeviceBootReceiver extends BroadcastReceiver {

    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"
                <action android:name="android.intent.action.BOOT_COMPLETED"/>

(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);

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;

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() {

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

  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 PKIX path building failed: 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();

        InputStream is = conn.getInputStream();
        FileOutputStream out = new FileOutputStream(path);
        copyStream (is, out);