org.boon.Exceptions类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.boon.Exceptions类的一些代码示例,展示了Exceptions类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exceptions类的具体详情如下:
包路径:org.boon.Exceptions
类名称:Exceptions

Exceptions介绍

暂无

代码示例

代码示例来源:origin: boonproject/boon

/**
 * Some quick validation for an expected value
 * @param expected expected this
 * @param got got this
 * @return returns true or throws an exception
 */
public static boolean equalsOrDie(long expected, long got) {
  if (expected != got) {
    return die(Boolean.class, "Expected was", expected, "but we got ", got);
  }
  return true;
}

代码示例来源:origin: boonproject/boon

@Override
public Object invokeStatic(Object... args) {
  try {
    return method.invoke(null, args);
  } catch ( Throwable ex ) {
    return handle( Object.class, ex,  "unable to invoke method", method,
        " with arguments", args );
  }
}

代码示例来源:origin: boonproject/boon

public static double[] grow( double[] array ) {
  Exceptions.requireNonNull( array );
  double[] newArray = new double[ array.length * 2 ];
  System.arraycopy( array, 0, newArray, 0, array.length );
  return newArray;
}

代码示例来源:origin: boonproject/boon

@Test (expected = Exceptions.SoftenedException.class)
public void die() {
  try {
    Exceptions.die( "Die" );
  } catch ( Exception e ) {
    Exceptions.handle( e );
  }
}

代码示例来源:origin: boonproject/boon

public static String postForm( final String url, final Map<String, ?> headers,
                final Map<String, Object> formData
) {
  return Exceptions.tryIt( String.class, new Exceptions.TrialWithReturn<String>() {
    @Override
    public String tryIt() throws Exception {
      URLConnection connection;
      connection = doPostFormData( url, headers, formData );
      return extractResponseString( connection );
    }
  } );
}

代码示例来源:origin: boonproject/boon

public static Response postBodyTextWithContentTypeReturnResponse(    final String url,
    final String contentType,
    final String body ) {
  return Exceptions.tryIt( Response.class, new Exceptions.TrialWithReturn<Response>() {
    @Override
    public Response tryIt() throws Exception {
      URLConnection connection;
      connection = doPost( url, null, contentType, null, body );
      return extractResponseObject( connection );
    }
  } );
}

代码示例来源:origin: boonproject/boon

public static void write( Path file, byte[] contents ) {
  try {
    Files.write( file, contents );
  } catch ( Exception ex ) {
    Exceptions.handle( ex );
  }
}

代码示例来源:origin: boonproject/boon

public static void  requireNonNulls(String message, Object... array) {
  int index = 0;
  for (Object obj : array) {
    if (obj == null)
      die(message, index);
    index++;
  }
}

代码示例来源:origin: boonproject/boon

public static long[] shrink( long[] array, int size ) {
  Exceptions.requireNonNull( array );
  long[] newArray = new long[ array.length - size ];
  System.arraycopy( array, 0, newArray, 0, array.length - size );
  return newArray;
}

代码示例来源:origin: boonproject/boon

public static String getWithHeaders(
    final String url,
    final Map<String, ?> headers ) {
  return Exceptions.tryIt( String.class, new Exceptions.TrialWithReturn<String>() {
    @Override
    public String tryIt() throws Exception {
      URLConnection connection;
      connection = doGet( url, headers, null, null );
      return extractResponseString( connection );
    }
  } );
}

代码示例来源:origin: boonproject/boon

public static Date fromISO8601_( String string ) {
  try {
    return new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssXXX" ).parse( string );
  } catch ( ParseException e ) {
    return Exceptions.handle ( Date.class, "Not a valid ISO8601", e );
  }
}

代码示例来源:origin: boonproject/boon

@Override
public Value put( String key, Value value ) {
  die( "Not that kind of map" );
  return null;
}

代码示例来源:origin: boonproject/boon

public static double[] grow( double[] array, final int size ) {
  Exceptions.requireNonNull( array );
  double[] newArray = new double[ array.length + size ];
  System.arraycopy( array, 0, newArray, 0, array.length );
  return newArray;
}

代码示例来源:origin: boonproject/boon

public static String postForm( final String url, final Map<String, ?> headers,
                final Map<String, Object> formData
) {
  return Exceptions.tryIt( String.class, new Exceptions.TrialWithReturn<String>() {
    @Override
    public String tryIt() throws Exception {
      URLConnection connection;
      connection = doPostFormData( url, headers, formData );
      return extractResponseString( connection );
    }
  } );
}

代码示例来源:origin: boonproject/boon

public static void _idx( final byte[] array, int startIndex, byte[] input, int length ) {
  try {
    System.arraycopy( input, 0, array, startIndex, length );
  } catch ( Exception ex ) {
    Exceptions.handle( String.format( "array size %d, startIndex %d, input length %d",
        array.length, startIndex, input.length ), ex );
  }
}

代码示例来源:origin: boonproject/boon

@Override
public MethodAccess bind(Object instance) {
  die("Bind does not work for cached methodAccess make a copy with methodAccsess() first");
  return null;
}

代码示例来源:origin: boonproject/boon

public static double[] grow( double[] array ) {
  Exceptions.requireNonNull( array );
  double[] newArray = new double[ array.length * 2 ];
  System.arraycopy( array, 0, newArray, 0, array.length );
  return newArray;
}

代码示例来源:origin: boonproject/boon

public static byte[] getBytes(
    final String url, final String contentType ) {
  return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() {
    @Override
    public byte[] tryIt() throws Exception {
      URLConnection connection;
      connection = doGet( url, null, contentType, null, true );
      return extractResponseBytes( connection );
    }
  } );
}

代码示例来源:origin: boonproject/boon

public static void write( OutputStream out, String content, Charset charset ) {
  try ( OutputStream o = out ) {
    o.write( content.getBytes( charset ) );
  } catch ( Exception ex ) {
    Exceptions.handle( ex );
  }
}

代码示例来源:origin: boonproject/boon

@Override
public boolean retainAll(Collection<?> c) {
  die("Not supported");
  return false;
}

相关文章