Search in sources :

Example 96 with ParseException

use of java.text.ParseException in project jersey by jersey.

the class MultiPartReaderWriterTest method testOne.

@Test
public void testOne() {
    final WebTarget target = target().path("multipart/one");
    try {
        final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
        checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
        assertEquals(1, result.getBodyParts().size());
        final BodyPart part = result.getBodyParts().get(0);
        checkMediaType(new MediaType("text", "plain"), part.getMediaType());
        checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());
        result.getParameterizedHeaders();
        result.cleanup();
    } catch (final IOException | ParseException e) {
        e.printStackTrace(System.out);
        fail("Caught exception: " + e);
    }
}
Also used : BodyPart(org.glassfish.jersey.media.multipart.BodyPart) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MediaType(javax.ws.rs.core.MediaType) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 97 with ParseException

use of java.text.ParseException in project jersey by jersey.

the class MultiPartReaderWriterTest method testTwo.

@Test
public void testTwo() {
    final WebTarget target = target().path("multipart/two");
    try {
        final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
        checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
        assertEquals(2, result.getBodyParts().size());
        final BodyPart part1 = result.getBodyParts().get(0);
        checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
        checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
        final BodyPart part2 = result.getBodyParts().get(1);
        checkMediaType(new MediaType("text", "xml"), part2.getMediaType());
        checkEntity("<outer><inner>value</inner></outer>", (BodyPartEntity) part2.getEntity());
        result.getParameterizedHeaders();
        result.cleanup();
    } catch (final IOException | ParseException e) {
        e.printStackTrace(System.out);
        fail("Caught exception: " + e);
    }
}
Also used : BodyPart(org.glassfish.jersey.media.multipart.BodyPart) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) MediaType(javax.ws.rs.core.MediaType) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 98 with ParseException

use of java.text.ParseException in project Android-Developers-Samples by johnjohndoe.

the class SyncAdapter method onPerformSync.

/**
     * Called by the Android system in response to a request to run the sync adapter. The work
     * required to read data from the network, parse it, and store it in the content provider is
     * done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter
     * run on a background thread. For this reason, blocking I/O and other long-running tasks can be
     * run <em>in situ</em>, and you don't have to set up a separate thread for them.
     .
     *
     * <p>This is where we actually perform any work required to perform a sync.
     * {@link android.content.AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread,
     * so it is safe to peform blocking I/O here.
     *
     * <p>The syncResult argument allows you to pass information back to the method that triggered
     * the sync.
     */
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    Log.i(TAG, "Beginning network synchronization");
    try {
        final URL location = new URL(FEED_URL);
        InputStream stream = null;
        try {
            Log.i(TAG, "Streaming data from network: " + location);
            stream = downloadUrl(location);
            updateLocalFeedData(stream, syncResult);
        // Makes sure that the InputStream is closed after the app is
        // finished using it.
        } finally {
            if (stream != null) {
                stream.close();
            }
        }
    } catch (MalformedURLException e) {
        Log.e(TAG, "Feed URL is malformed", e);
        syncResult.stats.numParseExceptions++;
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error reading from network: " + e.toString());
        syncResult.stats.numIoExceptions++;
        return;
    } catch (XmlPullParserException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (ParseException e) {
        Log.e(TAG, "Error parsing feed: " + e.toString());
        syncResult.stats.numParseExceptions++;
        return;
    } catch (RemoteException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    } catch (OperationApplicationException e) {
        Log.e(TAG, "Error updating database: " + e.toString());
        syncResult.databaseError = true;
        return;
    }
    Log.i(TAG, "Network synchronization complete");
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) ParseException(java.text.ParseException) RemoteException(android.os.RemoteException) URL(java.net.URL) OperationApplicationException(android.content.OperationApplicationException)

Example 99 with ParseException

use of java.text.ParseException in project Klyph by jonathangerbaud.

the class BirthdayAdapter method mergeViewWithData.

@Override
protected void mergeViewWithData(View view, GraphObject data) {
    super.mergeViewWithData(view, data);
    PicturePrimarySecondaryTextHolder holder = (PicturePrimarySecondaryTextHolder) getHolder(view);
    //holder.getPicture().setImageDrawable(null);
    Friend friend = (Friend) data;
    holder.getPrimaryText().setText(friend.getName());
    String birthday = friend.getBirthday();
    Date birthdayDate = null;
    String format = "MM/dd/y";
    try {
        birthdayDate = new SimpleDateFormat(format).parse(friend.getBirthday_date());
    } catch (ParseException e) {
    //e.printStackTrace();
    }
    if (birthdayDate != null) {
        Calendar dobDate = Calendar.getInstance();
        dobDate.setTime(birthdayDate);
        int year = dobDate.get(Calendar.YEAR);
        int month = dobDate.get(Calendar.MONTH);
        int day = dobDate.get(Calendar.DAY_OF_MONTH);
        Calendar today = Calendar.getInstance();
        today.set(Calendar.DAY_OF_MONTH, day);
        today.set(Calendar.MONTH, month);
        int curYear = today.get(Calendar.YEAR);
        int curMonth = today.get(Calendar.MONTH);
        int curDay = today.get(Calendar.DAY_OF_MONTH);
        int age = curYear - year;
        if (curMonth < month || (month == curMonth && curDay < day)) {
            age--;
        }
        birthday += " - " + getContext(holder.getPrimaryText()).getString(R.string.birthday_age, age);
    }
    holder.getSecondaryText().setText(birthday);
    loadImage(holder.getPicture(), friend.getPic(), AttrUtil.getResourceId(getContext(holder.getPrimaryText()), R.attr.squarePlaceHolderIcon), data);
}
Also used : Friend(com.abewy.android.apps.klyph.core.fql.Friend) Calendar(java.util.Calendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PicturePrimarySecondaryTextHolder(com.abewy.android.apps.klyph.adapter.holder.PicturePrimarySecondaryTextHolder)

Example 100 with ParseException

use of java.text.ParseException in project jfinal by jfinal.

the class DateKit method toDate.

public static Date toDate(String dateStr) {
    if (dateStr == null || "".equals(dateStr.trim())) {
        return null;
    }
    int length = dateStr.length();
    try {
        if (length == timeFormat.length()) {
            SimpleDateFormat sdfDate = new SimpleDateFormat(timeFormat);
            try {
                return sdfDate.parse(dateStr);
            } catch (ParseException e) {
                dateStr = dateStr.replace(".", "-");
                dateStr = dateStr.replace("/", "-");
                return sdfDate.parse(dateStr);
            }
        } else if (length == dateFormat.length()) {
            SimpleDateFormat sdfDate = new SimpleDateFormat(dateFormat);
            try {
                return sdfDate.parse(dateStr);
            } catch (ParseException e) {
                dateStr = dateStr.replace(".", "-");
                dateStr = dateStr.replace("/", "-");
                return sdfDate.parse(dateStr);
            }
        } else {
            throw new IllegalArgumentException("The date format is not supported for the time being.");
        }
    } catch (ParseException e) {
        throw new IllegalArgumentException("The date format is not supported for the time being.");
    }
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ParseException (java.text.ParseException)1141 Date (java.util.Date)435 SimpleDateFormat (java.text.SimpleDateFormat)387 IOException (java.io.IOException)118 DateFormat (java.text.DateFormat)117 Calendar (java.util.Calendar)104 ArrayList (java.util.ArrayList)98 Test (org.junit.Test)58 HashMap (java.util.HashMap)45 Matcher (java.util.regex.Matcher)39 File (java.io.File)38 GregorianCalendar (java.util.GregorianCalendar)34 Map (java.util.Map)28 BigDecimal (java.math.BigDecimal)23 Timestamp (java.sql.Timestamp)21 List (java.util.List)21 Locale (java.util.Locale)20 SipException (javax.sip.SipException)20 InputStream (java.io.InputStream)19 TimeZone (java.util.TimeZone)19