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);
}
}
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);
}
}
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");
}
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);
}
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.");
}
}
Aggregations