Example usage for java.lang UnknownError UnknownError

List of usage examples for java.lang UnknownError UnknownError

Introduction

In this page you can find the example usage for java.lang UnknownError UnknownError.

Prototype

public UnknownError(String s) 

Source Link

Document

Constructs an UnknownError with the specified detail message.

Usage

From source file:Main.java

public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError {

    ApplicationInfo appInfo = appContext.getApplicationInfo();

    String pkg = appContext.getPackageName();
    int uid = appInfo.uid;
    Class appOpsClass = null;//  w w  w.j  a v a2  s . co  m
    Object appOps = appContext.getSystemService("appops");

    try {

        appOpsClass = Class.forName("android.app.AppOpsManager");

        Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
                String.class);

        Field opValue = appOpsClass.getDeclaredField(appOpsServiceId);

        int value = (int) opValue.getInt(Integer.class);
        Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg);

        return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED

    } catch (ClassNotFoundException e) {
        throw new UnknownError("class not found");
    } catch (NoSuchMethodException e) {
        throw new UnknownError("no such method");
    } catch (NoSuchFieldException e) {
        throw new UnknownError("no such field");
    } catch (InvocationTargetException e) {
        throw new UnknownError("invocation target");
    } catch (IllegalAccessException e) {
        throw new UnknownError("illegal access");
    }

}

From source file:org.dmlc.xgboost4j.DMatrix.java

/**
 * create DMatrix from sparse matrix//from   w  w w .j  a va 2s. co m
 * @param headers index to headers (rowHeaders for CSR or colHeaders for CSC)
 * @param indices Indices (colIndexs for CSR or rowIndexs for CSC)
 * @param data non zero values (sequence by row for CSR or by col for CSC)
 * @param st sparse matrix type (CSR or CSC)
 * @throws org.dmlc.xgboost4j.util.XGBoostError
 */
public DMatrix(long[] headers, int[] indices, float[] data, SparseType st) throws XGBoostError {
    long[] out = new long[1];
    if (st == SparseType.CSR) {
        ErrorHandle.checkCall(XgboostJNI.XGDMatrixCreateFromCSR(headers, indices, data, out));
    } else if (st == SparseType.CSC) {
        ErrorHandle.checkCall(XgboostJNI.XGDMatrixCreateFromCSC(headers, indices, data, out));
    } else {
        throw new UnknownError("unknow sparsetype");
    }
    handle = out[0];
}

From source file:ctrus.pa.bow.core.BOWOptionsImpl.java

public final boolean hasOptionInternal(String option, boolean isInternal) {

    if (isInternal) {
        return _internalOptions.containsKey(option);
    } else {/*  ww w . ja  v  a 2s  .c  om*/
        if (_parsedOptions == null)
            throw new UnknownError("CLI not parsed yet!");
        return _parsedOptions.hasOption(option);
    }

}

From source file:ml.dmlc.xgboost4j.java.DMatrix.java

/**
 * Create DMatrix from Sparse matrix in CSR/CSC format.
 * @param headers The row index of the matrix.
 * @param indices The indices of presenting entries.
 * @param data The data content./*from   www . j  a v a  2  s. c  om*/
 * @param st  Type of sparsity.
 * @throws XGBoostError
 */
@Deprecated
public DMatrix(long[] headers, int[] indices, float[] data, SparseType st) throws XGBoostError {
    long[] out = new long[1];
    if (st == SparseType.CSR) {
        JNIErrorHandle.checkCall(XGBoostJNI.XGDMatrixCreateFromCSREx(headers, indices, data, 0, out));
    } else if (st == SparseType.CSC) {
        JNIErrorHandle.checkCall(XGBoostJNI.XGDMatrixCreateFromCSCEx(headers, indices, data, 0, out));
    } else {
        throw new UnknownError("unknow sparsetype");
    }
    handle = out[0];
}

From source file:ml.dmlc.xgboost4j.java.DMatrix.java

/**
 * Create DMatrix from Sparse matrix in CSR/CSC format.
 * @param headers The row index of the matrix.
 * @param indices The indices of presenting entries.
 * @param data The data content./*from   w  ww .  ja va  2s.  c  o  m*/
 * @param st  Type of sparsity.
 * @param shapeParam   when st is CSR, it specifies the column number, otherwise it is taken as
 *                     row number
 * @throws XGBoostError
 */
public DMatrix(long[] headers, int[] indices, float[] data, SparseType st, int shapeParam) throws XGBoostError {
    long[] out = new long[1];
    if (st == SparseType.CSR) {
        JNIErrorHandle.checkCall(XGBoostJNI.XGDMatrixCreateFromCSREx(headers, indices, data, shapeParam, out));
    } else if (st == SparseType.CSC) {
        JNIErrorHandle.checkCall(XGBoostJNI.XGDMatrixCreateFromCSCEx(headers, indices, data, shapeParam, out));
    } else {
        throw new UnknownError("unknow sparsetype");
    }
    handle = out[0];
}

From source file:org.kalypso.model.wspm.tuhh.ui.resolutions.AbstractProfilMarkerResolution.java

@Override
public void run(final IMarker marker) {
    final CommandableWorkspace ws = getWorkspace(marker);

    Feature feature;/*from w  ww .  j  ava2 s.  c om*/
    try {
        final String profileFeatureId = marker
                .getAttribute(IValidatorMarkerCollector.MARKER_ATTRIBUTE_PROFILE_ID).toString();
        feature = ws == null ? null : ws.getFeature(profileFeatureId);

        if (feature != null) {
            final IProfile profil = ((IProfileFeature) feature).getProfile();
            if (profil != null) {
                if (resolve(profil)) {
                    marker.delete();// delete marker because ProblemView is no Listener on GMLWorkspace
                    // final ICommand command = new ChangeFeaturesCommand( ws, ProfileFeatureFactory.toFeatureAsChanges( profil,
                    // feature ) );
                    // ws.postCommand( command );
                }
            }
        }
    } catch (final Exception e) {
        throw new UnknownError(e.getLocalizedMessage());
    }

}

From source file:de.elanev.studip.android.app.frontend.courses.CourseAttendeesFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;//from ww  w.j  a  v a 2s  . co  m
    }

    List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>();
    cursor.moveToFirst();
    int prevRole = -1;
    int currRole = -1;
    while (!cursor.isAfterLast()) {
        currRole = cursor
                .getInt(cursor.getColumnIndex(CoursesContract.Columns.CourseUsers.COURSE_USER_USER_ROLE));
        if (currRole != prevRole) {
            String role = null;
            switch (currRole) {
            case CoursesContract.USER_ROLE_TEACHER:
                role = getString(R.string.Teacher);
                break;
            case CoursesContract.USER_ROLE_TUTOR:
                role = getString(R.string.Tutor);
                break;
            case CoursesContract.USER_ROLE_STUDENT:
                role = getString(R.string.Student);
                break;
            default:
                throw new UnknownError("unknown role type");
            }
            sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(), role));
        }

        prevRole = currRole;

        cursor.moveToNext();
    }

    mUsersAdapter.setSections(sections);
    mUsersAdapter.changeCursor(cursor);

    setLoadingViewVisible(false);
}

From source file:edu.kit.dama.mdm.content.impl.BessMetadataExtractor.java

@Override
protected void configureExtractor(Properties pProperties) {
    // <editor-fold defaultstate="collapsed" desc="Check and set version property">
    LOGGER.debug("configureExtractor() -- configure properties");
    String version = pProperties.getProperty(VERSION_PROPERTY, VERSION_1_0);
    VersionString actualVersion = VersionString.VERSION10;
    try {// w  w w  .jav a  2 s  . c o m
        actualVersion = VersionString.getEnum(version);
    } catch (IllegalArgumentException iae) {
        LOGGER.warn("Failed to parse version from property value {}. Using default value '{}'", version,
                actualVersion);
    }
    // Test for valid entry
    switch (actualVersion) {
    case VERSION10:
        break;
    case VERSION20:
    default:
        LOGGER.error("'" + actualVersion + "' is not a supported version!");
        throw new UnknownError("'" + actualVersion + "' is not a supported version!");
    }
    // </editor-fold>
    LOGGER.debug("chosen version: " + actualVersion);
}

From source file:io.github.retz.web.Client.java

public int getBinaryFile(int id, String file, OutputStream out) throws IOException {
    String date = TimestampHelper.now();
    String resource = "/job/" + id + "/download?path=" + file;
    AuthHeader header = authenticator.header("GET", "", date, resource);
    URL url = new URL(uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + resource); // TODO url-encode!
    LOG.info("Fetching {}", url);
    HttpURLConnection conn;/*ww w . java2  s.c  o m*/

    conn = (HttpURLConnection) url.openConnection();
    //LOG.info("classname> {}", conn.getClass().getName());
    if (uri.getScheme().equals("https") && !checkCert && conn instanceof HttpsURLConnection) {
        if (verboseLog) {
            LOG.warn(
                    "DANGER ZONE: TLS certificate check is disabled. Set 'retz.tls.insecure = false' at config file to supress this message.");
        }
        HttpsURLConnection sslCon = (HttpsURLConnection) conn;
        if (socketFactory != null) {
            sslCon.setSSLSocketFactory(socketFactory);
        }
        if (hostnameVerifier != null) {
            sslCon.setHostnameVerifier(hostnameVerifier);
        }
    }
    conn.setRequestMethod("GET");
    conn.setRequestProperty("Accept", "application/octet-stream");
    conn.setRequestProperty("Authorization", header.buildHeader());
    conn.setRequestProperty("Date", date);
    conn.setRequestProperty("Content-md5", "");
    conn.setDoInput(true);
    String s2s = authenticator.string2sign("GET", "", date, resource);
    LOG.debug("Authorization: {} / S2S={}", header.buildHeader(), s2s);

    if (conn.getResponseCode() != 200) {
        if (verboseLog) {
            LOG.warn("HTTP Response:", conn.getResponseMessage());
        }
        if (conn.getResponseCode() < 200) {
            throw new AssertionError(conn.getResponseMessage());
        } else if (conn.getResponseCode() == 404) {
            throw new FileNotFoundException(url.toString());
        } else {
            String message;
            try {
                Response response = MAPPER.readValue(conn.getErrorStream(), Response.class);
                message = response.status();
                LOG.error(message, response);
            } catch (JsonProcessingException e) {
                message = e.toString();
                LOG.error(message, e);
            }
            throw new UnknownError(message);
        }
    }

    int size = conn.getContentLength();
    if (size < 0) {
        throw new IOException("Illegal content length:" + size);
    } else if (size == 0) {
        // not bytes to save;
        return 0;
    }
    try {
        return IOUtils.copy(conn.getInputStream(), out);
    } finally {
        conn.disconnect();
    }
}

From source file:net.bull.javamelody.TestMonitoringFilter.java

/** Test.
 * @throws ServletException e//from   w ww.j av a  2 s.  c  o  m
 * @throws IOException e */
@Test
public void testDoFilter() throws ServletException, IOException {
    // displayed-counters
    setProperty(Parameter.DISPLAYED_COUNTERS, "sql");
    try {
        setUp();
        doFilter(createNiceMock(HttpServletRequest.class));
        setProperty(Parameter.DISPLAYED_COUNTERS, "");
        setUp();
        doFilter(createNiceMock(HttpServletRequest.class));
        setProperty(Parameter.DISPLAYED_COUNTERS, "unknown");
        try {
            setUp();
            doFilter(createNiceMock(HttpServletRequest.class));
        } catch (final IllegalArgumentException e) {
            assertNotNull("ok", e);
        }
    } finally {
        setProperty(Parameter.DISPLAYED_COUNTERS, null);
    }

    // url exclue
    setProperty(Parameter.URL_EXCLUDE_PATTERN, ".*");
    try {
        setUp();
        doFilter(createNiceMock(HttpServletRequest.class));
    } finally {
        setProperty(Parameter.URL_EXCLUDE_PATTERN, "");
    }

    // standard
    setUp();
    doFilter(createNiceMock(HttpServletRequest.class));

    // log
    setUp();
    setProperty(Parameter.LOG, TRUE);
    try {
        ((Logger) org.slf4j.LoggerFactory.getLogger(FILTER_NAME)).setLevel(Level.WARN);
        doFilter(createNiceMock(HttpServletRequest.class));

        ((Logger) org.slf4j.LoggerFactory.getLogger(FILTER_NAME)).setLevel(Level.DEBUG);
        doFilter(createNiceMock(HttpServletRequest.class));

        final HttpServletRequest request = createNiceMock(HttpServletRequest.class);
        expect(request.getHeader("X-Forwarded-For")).andReturn("me").anyTimes();
        expect(request.getQueryString()).andReturn("param1=1").anyTimes();
        doFilter(request);
    } finally {
        setProperty(Parameter.LOG, null);
    }

    // ajax
    final HttpServletRequest request = createNiceMock(HttpServletRequest.class);
    expect(request.getHeader("X-Requested-With")).andReturn("XMLHttpRequest");
    doFilter(request);

    // erreur systme http, avec log
    setProperty(Parameter.LOG, TRUE);
    try {
        final String test = "test";
        doFilter(createNiceMock(HttpServletRequest.class), new UnknownError(test));
        doFilter(createNiceMock(HttpServletRequest.class), new IllegalStateException(test));
        // pas possibles:
        //         doFilter(createNiceMock(HttpServletRequest.class), new IOException(test));
        //         doFilter(createNiceMock(HttpServletRequest.class), new ServletException(test));
        //         doFilter(createNiceMock(HttpServletRequest.class), new Exception(test));
    } finally {
        setProperty(Parameter.LOG, null);
    }

    setProperty(Parameter.RUM_ENABLED, TRUE);
    try {
        setUp();
        final HttpServletRequest requestForRum = createNiceMock(HttpServletRequest.class);
        expect(requestForRum.getHeader("accept")).andReturn("text/html");
        expect(requestForRum.getInputStream())
                .andReturn(createInputStreamForString("<html><body>test</body></html>")).anyTimes();
        doFilter(requestForRum);
    } finally {
        setProperty(Parameter.RUM_ENABLED, null);
    }
}