Example usage for java.io SyncFailedException SyncFailedException

List of usage examples for java.io SyncFailedException SyncFailedException

Introduction

In this page you can find the example usage for java.io SyncFailedException SyncFailedException.

Prototype

public SyncFailedException(String desc) 

Source Link

Document

Constructs an SyncFailedException with a detail message.

Usage

From source file:de.ribeiro.android.gso.core.UntisProvider.java

/**
 * Ldt die Selectoren(wochen/elemente/typen) von der GSO Seite und parsed
 * diese in den StupidCore//from w w w  .ja v  a  2s .  co m
 *
 * @param logger
 * @param htmlResponse
 * @param getProfil    ()
 * @throws Exception
 * @author Tobias Janssen
 */
public static void syncTypeList(HtmlResponse htmlResponse, Profil mProfil) throws Exception {

    JSONArray clsarray = null;
    JSONArray teacherarray = null;
    JSONArray roomarray = null;
    GregorianCalendar date = new GregorianCalendar();
    // session erzeugen und cookies abholen
    //TODO: Remove hardcoded URL
    String url = "https://webuntis.stadt-koeln.de/WebUntis/Timetable.do?request.preventCache="
            + date.getTimeInMillis() + "&school=K175055";
    HttpSession session = new HttpSession(url + 1);
    //5 Wochen in die Zukunft schauen
    for (int i = 0; i < 5; i++) {
        try {
            if (clsarray == null && (clsarray = RequestUrl(session, url, "1")) == null) {
                date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7));
                session.SetStupidServerDate(date, i + 1);
                continue;
            }

            if (teacherarray == null && (teacherarray = RequestUrl(session, url, "2")) == null) {
                date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7));
                session.SetStupidServerDate(date, i + 1);
                continue;
            }

            if (roomarray == null && (roomarray = RequestUrl(session, url, "4")) == null) {
                date.setTimeInMillis(date.getTimeInMillis() + (1000 * 60 * 60 * 24 * 7));
                session.SetStupidServerDate(date, i + 1);
                continue;
            }
            session.Close();
            _logger.Info("new Elements downloaded!");
            mProfil.types.htmlModDate = htmlResponse.lastModified;
            break;
        } catch (Exception e) {
            throw new SyncFailedException(e.getMessage());
        }
    }
    Type type = new Type();
    type.elementList = ConvertJSonArray(clsarray);
    type.typeName = "Klassen";
    type.type = "1";
    AddTypeToProfil(mProfil, type);

    type = new Type();
    type.elementList = ConvertJSonArray(teacherarray);
    type.typeName = "Lehrer";
    type.type = "2";
    AddTypeToProfil(mProfil, type);

    type = new Type();
    type.elementList = ConvertJSonArray(roomarray);
    type.typeName = "Rume";
    type.type = "4";
    AddTypeToProfil(mProfil, type);

    mProfil.isDirty = true;
}

From source file:org.apache.hadoop.hbase.client.TestFastFailWithoutTestUtil.java

@Test
public void testExceptionsIdentifiedByInterceptor() throws IOException {
    Throwable[] networkexceptions = new Throwable[] { new ConnectException("Mary is unwell"),
            new SocketTimeoutException("Mike is too late"), new ClosedChannelException(),
            new SyncFailedException("Dave is not on the same page"), new TimeoutException("Mike is late again"),
            new EOFException("This is the end... "), new ConnectionClosingException("Its closing") };
    final String INDUCED = "Induced";
    Throwable[] nonNetworkExceptions = new Throwable[] { new IOException("Bob died"),
            new RemoteException("Bob's cousin died", null), new NoSuchMethodError(INDUCED),
            new NullPointerException(INDUCED), new DoNotRetryIOException(INDUCED), new Error(INDUCED) };

    Configuration conf = HBaseConfiguration.create();
    long CLEANUP_TIMEOUT = 0;
    long FAST_FAIL_THRESHOLD = 1000000;
    conf.setBoolean(HConstants.HBASE_CLIENT_FAST_FAIL_MODE_ENABLED, true);
    conf.setLong(HConstants.HBASE_CLIENT_FAST_FAIL_CLEANUP_MS_DURATION_MS, CLEANUP_TIMEOUT);
    conf.setLong(HConstants.HBASE_CLIENT_FAST_FAIL_THREASHOLD_MS, FAST_FAIL_THRESHOLD);
    for (Throwable e : networkexceptions) {
        PreemptiveFastFailInterceptor interceptor = TestFastFailWithoutTestUtil
                .createPreemptiveInterceptor(conf);
        FastFailInterceptorContext context = (FastFailInterceptorContext) interceptor.createEmptyContext();

        RetryingCallable<?> callable = getDummyRetryingCallable(getSomeServerName());
        context.prepare(callable, 0);/*from w w w  . j  a  va2  s .co  m*/
        interceptor.intercept(context);
        interceptor.handleFailure(context, e);
        interceptor.updateFailureInfo(context);
        assertTrue("The call shouldn't have been successful if there was a ConnectException",
                context.getCouldNotCommunicateWithServer().booleanValue());
    }
    for (Throwable e : nonNetworkExceptions) {
        try {
            PreemptiveFastFailInterceptor interceptor = TestFastFailWithoutTestUtil
                    .createPreemptiveInterceptor(conf);
            FastFailInterceptorContext context = (FastFailInterceptorContext) interceptor.createEmptyContext();

            RetryingCallable<?> callable = getDummyRetryingCallable(getSomeServerName());
            context.prepare(callable, 0);
            interceptor.intercept(context);
            interceptor.handleFailure(context, e);
            interceptor.updateFailureInfo(context);
            assertFalse("The call shouldn't have been successful if there was a ConnectException",
                    context.getCouldNotCommunicateWithServer().booleanValue());
        } catch (NoSuchMethodError t) {
            assertTrue("Exception not induced", t.getMessage().contains(INDUCED));
        } catch (NullPointerException t) {
            assertTrue("Exception not induced", t.getMessage().contains(INDUCED));
        } catch (DoNotRetryIOException t) {
            assertTrue("Exception not induced", t.getMessage().contains(INDUCED));
        } catch (Error t) {
            assertTrue("Exception not induced", t.getMessage().contains(INDUCED));
        }
    }
}

From source file:ValidateLicenseHeaders.java

/**
 * Replace a legacy jboss header with the current default header
 * /*from w ww. j  a  v a  2 s .  co m*/
 * @param javaFile -
 *          the java source file
 * @param endOfHeader -
 *          the offset to the end of the legacy header
 * @throws IOException -
 *           thrown on failure to replace the header
 */
static void replaceHeader(File javaFile, long endOfHeader) throws IOException {
    if (log.isLoggable(Level.FINE))
        log.fine("Replacing legacy jboss header in: " + javaFile);
    RandomAccessFile raf = new RandomAccessFile(javaFile, "rw");
    File bakFile = new File(javaFile.getAbsolutePath() + ".bak");
    FileOutputStream fos = new FileOutputStream(bakFile);
    fos.write(DEFAULT_HEADER.getBytes());
    FileChannel fc = raf.getChannel();
    long count = raf.length() - endOfHeader;
    fc.transferTo(endOfHeader, count, fos.getChannel());
    fc.close();
    fos.close();
    raf.close();
    if (javaFile.delete() == false)
        log.severe("Failed to delete java file: " + javaFile);
    if (bakFile.renameTo(javaFile) == false)
        throw new SyncFailedException("Failed to replace: " + javaFile);
}

From source file:org.linphone.ContactEditorFragment.java

private void setContactPhoto() {
    ContentResolver cr = getActivity().getContentResolver();
    Uri updateUri = ContactsContract.Data.CONTENT_URI;

    if (photoToAdd != null) {
        //New contact
        if (isNewContact) {
            ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID)
                    .withValue(ContactsContract.Data.MIMETYPE,
                            ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                    .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build());
        } else { //update contact picture
            String w = ContactsContract.Data.CONTACT_ID + "='" + contact.getID() + "' AND "
                    + ContactsContract.Data.MIMETYPE + " = '"
                    + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";

            Cursor queryCursor = cr.query(updateUri, new String[] { ContactsContract.Data._ID }, w, null, null);
            if (queryCursor == null) {
                try {
                    throw new SyncFailedException("EE");
                } catch (SyncFailedException e) {
                    e.printStackTrace();
                }//from  w w w . j  a va2 s  .  c om
            } else {
                if (contact.getPhoto() == null) {
                    String rawContactId = ContactsManager.getInstance().findRawContactID(cr,
                            String.valueOf(contactID));
                    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                            .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
                            .withValue(ContactsContract.Data.MIMETYPE,
                                    ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build());
                }

                if (queryCursor.moveToFirst()) { // otherwise no photo
                    int colIdx = queryCursor.getColumnIndex(ContactsContract.Data._ID);
                    long id = queryCursor.getLong(colIdx);

                    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                            .withSelection(ContactsContract.Data._ID + "= ?",
                                    new String[] { String.valueOf(id) })
                            .withValue(ContactsContract.Data.MIMETYPE,
                                    ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                            .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd).build());
                }
                queryCursor.close();
            }
        }
    }
}