Categories
discuss

Android Parse SDK i/o failure unknown format (magic number 227b)

I am trying to recover my records from Parse. The class is called Rating. When I try to find less than 5 records, there are no problems. But when I try to find more records, the next stack is shown:

com.parse.ParseRequest$ParseRequestException: i/o failure
at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:289)
at com.parse.ParseRequest$2.then(ParseRequest.java:144)
at com.parse.ParseRequest$2.then(ParseRequest.java:138)
at bolts.Task$15.run(Task.java:839)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.io.IOException: unknown format (magic number 227b)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:101)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
at com.parse.ParseDecompressInterceptor.intercept(ParseDecompressInterceptor.java:40)
at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147)
at com.parse.ParsePlugins$1.intercept(ParsePlugins.java:115)
at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147)
at com.parse.ParseHttpClient.execute(ParseHttpClient.java:122)
at com.parse.ParseRequest$3.then(ParseRequest.java:135)
at com.parse.ParseRequest$3.then(ParseRequest.java:132)
at bolts.Task$15.run(Task.java:839)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
at bolts.Task.completeAfterTask(Task.java:830)
at bolts.Task.continueWithTask(Task.java:642)
at bolts.Task.continueWithTask(Task.java:653)
at bolts.Task$13.then(Task.java:745)
at bolts.Task$13.then(Task.java:733)
... 4 more

Anyone has any clue why this is happening?

Answer

To make it work I am using the 1.11.0 version ( compile ‘com.parse:parse-android:1.11.0’ ). So far no problems.

Categories
discuss

Convert byte[] to image and display on jsp

I’m trying to display an uploaded picture (which is now a byte array) on a jsp page. Now, the byte[] column exists in the database and has to be converted to an image.

This is what I’ve been trying:

Part of the table on jsp page:

<c:forEach var="user" items="${userList}">
    <tr>
        <td>${user.fileName}</td>
        <td>
            <img src="data:image/jpg;base64,${user.imageFile}" alt="No image">
        </td>

Part of the controller that takes an array of bytes from a MultipartFile object:

@RequestMapping(value = "/register", method = RequestMethod.POST)
    public ModelAndView userRegister(@ModelAttribute("user") @Valid User user, BindingResult result, ModelMap model, @RequestParam("fileData") MultipartFile fileData) throws Exception {

            if (!fileData.isEmpty() && fileData != null) {                

                byte[] bytes = fileData.getBytes();
                user.setFileName(fileData.getOriginalFilename());
                user.setImageFile(bytes);
            }
        }

If any additional information is needed, please let me know. Thanks.

Answer

You can add a tranisent base64imageFile property to your User. It will hold the base64 encoded string of the image, which you can access in your jsp like

<img alt="img" src="data:image/jpeg;base64,${user.base64imageFile}"/>

And in your method you should do the encoding, somethig like

@RequestMapping(value = "/register", method = RequestMethod.POST)
    public ModelAndView userRegister(@ModelAttribute("user") @Valid User user, BindingResult result, ModelMap model, @RequestParam("fileData") MultipartFile fileData) throws Exception {
        if (!fileData.isEmpty() && fileData != null) {                
            byte[] bytes = fileData.getBytes();
            user.setFileName(fileData.getOriginalFilename());
            user.setImageFile(bytes);
            byte[] encodeBase64 = Base64.encodeBase64(bytes);
            String base64Encoded = new String(encodeBase64, "UTF-8");
            user.setBase64image(base64encoded);
        }
    }

IOUtils and Base64 are a handy util classes from org.apache.commons, shouldn’t have a problem finding

Categories
discuss

Android Marshmallow Text Selection Option Menu Actions

Hi I would like to add a global text selection listener which shows a sub menu for a any selected text. Android 6 allows this with the new Text Selection listener.

enter image description here

Is it possible to use this functionality by an external app, which then populates the sub menu?

Answer

The concept is called ACTION_PROCESS_TEXT and is available in Android 6:

Define an intent filter in your Manifest:

<activity android:name=".YourActivity" 
          android:label="@string/process_text_action_name">
    <intent-filter>
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
</activity>

Then handle the intent in your activity:

Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.process_text_main);
  CharSequence text = getIntent()
      .getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
  // process the text
  boolean readonly = getIntent()
  .getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
}

You can only define one Action per Activity.

Source

Example

Categories
discuss

Java 1.8.65 javac is missing

I downloaded the newst 1.8.65 JDK a few days ago an the javac file is missing

in case someone believes I accidently downloaded the JRE, here are 2 screenshots

oracle

when I browse to the directory I installed the JDK in

C:EnwicklungJDK1.8.65bin

the javac.exe file isn’t there where it should be, as you can see in this second screenshot

folder

can anyone confirm this? tried to install the JDK a second time without any change.

EDIT: of course I searched the whole drive for a javac.exe, no match was found

Answer

I was able to solve the “problem” myself. after rechecking every letter of the installation process.

During installation, the installer asks you where you want to install the JDK

enter image description here

I chose the folder C:EnwicklungJDK1.8.65

A progress bar is displayed and installation continues

Then you are asked

enter image description here

for non-German native speakers

Zielordner = target folder Ändern = change

In this view, the installation process is asking in which folder I want to install Java

I chose the folder C:EntwicklungJDK1.8.65 again this leads to the following conflict

in C:EntwicklungJDK1.8.65 there was a bin folder of the JDK installation

The JRE aka its alias Java, which a mindful reader should have noticed, but I obviously missed twice, was installed in the same location overwriting the bin folder of the JDK with the bin folder of the JRE, deleting all files.

enter image description here

An unneeded mistake on my side. Unfortunately, the German installation process doesn’t state anywhere that the JRE is being installed except in the folder name of the Zielorder view and that it’s installed in the base folder structure.

In my defense, the installation process does not state explicitly that the JRE is being installed next and the installation, at least in this German version, doesn’t warn that folders and files are going to be overwritten, which is an undesirable effect from my point of view.

NOTE: I left the predefined folder name as C:Program FilesJavajre1.8.0_65 because otherwise after changing it to C:EntwicklungJDK1.8.65 there would have been no indication for you to know that the JRE is being installed

Categories
discuss

Spring Boot: Load @Value from YAML file

I need to load a property from a .yml file, which contains the path to a folder where the application can read files from.

I’m using the following code to inject the property:

@Value("${files.upload.baseDir}")
private String pathToFileFolder;

The .yml file for development is located under src/main/resources/config/application.yml, im running the application with the following command in production, to override the development settings:

java -jar app.jar --spring.config.location=/path/to/application-production.yml

The Spring Boot documentation says:

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:

  1. A /config subdirectory of the current directory.

  2. The current directory

  3. A classpath /config package

  4. The classpath root

As well as:

You can also use YAML (‘.yml’) files as an alternative to ‘.properties’.

The .yml file contains:

{...}
files:
      upload:
        baseDir: /Users/Thomas/Code/IdeaProjects/project1/files
{...}

And my Application class is annotated with:

@SpringBootApplication
@EnableCaching

When I run the application, i get an exception:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'files.upload.baseDir' in string value "${files.upload.baseDir}"

Do I have to use the YamlPropertySourceLoader class or add a special annotation to enable the support for .yml in Spring Boot?

Edit: The .yml file contains some other properties, which get successfully loaded by Spring Boot like dataSource.XXXor hibernate.XXX.

Answer

M. Deinum is right, the setup i’ve provided is working – the yml file was indented wrong, so the property couldn’t be found.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..