當前位置: 首頁>>代碼示例>>Java>>正文


Java IOException類代碼示例

本文整理匯總了Java中java.io.IOException的典型用法代碼示例。如果您正苦於以下問題:Java IOException類的具體用法?Java IOException怎麽用?Java IOException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IOException類屬於java.io包,在下文中一共展示了IOException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFrames

import java.io.IOException; //導入依賴的package包/類
static ArrayList<BufferedImage> getFrames(File gif) throws IOException {
    ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
    ImageReader ir = new GIFImageReader(new GIFImageReaderSpi());
    ir.setInput(ImageIO.createImageInputStream(gif));
    for (int i = 0; i < ir.getNumImages(true); i++) {
        frames.add(ir.read(i));
    }
    // Release resources for Garbage Collection
    ir.dispose();
    return frames;
}
 
開發者ID:phweda,項目名稱:MFM,代碼行數:12,代碼來源:VideoUtils.java

示例2: getSamples

import java.io.IOException; //導入依賴的package包/類
public List<ByteBuffer> getSamples() {
    List<ByteBuffer> samples = new LinkedList<ByteBuffer>();
    long lastEnd = 0;
    for (Line sub : subs) {
        long silentTime = sub.from - lastEnd;
        if (silentTime > 0) {
            samples.add(ByteBuffer.wrap(new byte[]{0, 0}));
        } else if (silentTime < 0) {
            throw new Error("Subtitle display times may not intersect");
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        try {
            dos.writeShort(sub.text.getBytes("UTF-8").length);
            dos.write(sub.text.getBytes("UTF-8"));
            dos.close();
        } catch (IOException e) {
            throw new Error("VM is broken. Does not support UTF-8");
        }
        samples.add(ByteBuffer.wrap(baos.toByteArray()));
        lastEnd = sub.to;
    }
    return samples;
}
 
開發者ID:begeekmyfriend,項目名稱:mp4parser_android,代碼行數:25,代碼來源:QuicktimeTextTrackImpl.java

示例3: getObservableAddressFromLocation

import java.io.IOException; //導入依賴的package包/類
public Observable<Address> getObservableAddressFromLocation(final double latitude, final double longitude,
                                                            final Context context) {
    return new Observable<Address>() {
        @Override
        protected void subscribeActual(Observer<? super Address> observer) {
            Geocoder geocoder = new Geocoder(context, Locale.getDefault());
            try {
                List<Address> addressList = geocoder.getFromLocation(
                        latitude, longitude, 1);
                if (addressList != null && addressList.size() > 0) {
                    address = addressList.get(0);
                    observer.onNext(address);
                }
            } catch (IOException e) {
                Log.e(TAG, "Unable connect to Geocoder", e);
            }

        }
    }.subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread());
}
 
開發者ID:aliumujib,項目名稱:Nibo,代碼行數:22,代碼來源:LocationAddress.java

示例4: writeObject

import java.io.IOException; //導入依賴的package包/類
private void writeObject(ObjectOutputStream s)
    throws IOException
{
    Iterator<Map.Entry<K,V>> i =
        (size > 0) ? entrySet0().iterator() : null;

    // Write out the threshold, loadfactor, and any hidden stuff
    s.defaultWriteObject();

    // Write out number of buckets
    s.writeInt(table.length);

    // Write out size (number of Mappings)
    s.writeInt(size);

    // Write out keys and values (alternating)
    if (i != null) {
        while (i.hasNext()) {
            Map.Entry<K,V> e = i.next();
            s.writeObject(e.getKey());
            s.writeObject(e.getValue());
        }
    }
}
 
開發者ID:DStream-Storm,項目名稱:DStream,代碼行數:25,代碼來源:SynopsisHashMap.java

示例5: _renderParagraph

import java.io.IOException; //導入依賴的package包/類
/**
 * Renders the currently opened paragraph with the currently buffered content,
 * escaping it if necessary, then close it and flush the buffer.
 *
 * @param rw      the response writer used to put content in the underlying
 *                response.
 * @param bean    the property holder for the rendered document.
 * @param builder the content buffer
 *
 * @throws IOException if a problem occurs while writing the content to the
 *                     underlying response.
 */
private void _renderParagraph(
  FacesContext  context,
  StringBuilder builder
  ) throws IOException
{
  // Pre-conditions that would cause NullPointerException if not met
  assert builder != null;
  assert context != null;

  renderFormattedText(context, builder.toString());

  context.getResponseWriter().endElement(_PARAGRAPH_ELEMENT);

  // Clear buffer content
  builder.delete(0, builder.length());
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:29,代碼來源:OutputDocumentRenderer.java

示例6: testServerNotAvailable

import java.io.IOException; //導入依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet
public void testServerNotAvailable() throws Exception {
    URL url = new URL(NativeTestServer.getFileURL("/success.txt"));
    HttpURLConnection urlConnection =
            (HttpURLConnection) url.openConnection();
    assertEquals("this is a text file\n", TestUtil.getResponseAsString(urlConnection));
    // After shutting down the server, the server should not be handling
    // new requests.
    NativeTestServer.shutdownNativeTestServer();
    HttpURLConnection secondConnection =
            (HttpURLConnection) url.openConnection();
    // Default implementation reports this type of error in connect().
    // However, since Cronet's wrapper only receives the error in its listener
    // callback when message loop is running, Cronet's wrapper only knows
    // about the error when it starts to read response.
    try {
        secondConnection.getResponseCode();
        fail();
    } catch (IOException e) {
        assertTrue(e instanceof java.net.ConnectException
                || e instanceof UrlRequestException);
        assertTrue((e.getMessage().contains("ECONNREFUSED")
                || (e.getMessage().contains("Connection refused"))
                || e.getMessage().contains("net::ERR_CONNECTION_REFUSED")));
    }
    checkExceptionsAreThrown(secondConnection);
    // Starts the server to avoid crashing on shutdown in tearDown().
    assertTrue(NativeTestServer.startNativeTestServer(getContext()));
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:32,代碼來源:CronetHttpURLConnectionTest.java

示例7: tryOpen

import java.io.IOException; //導入依賴的package包/類
/**
 * Try to open the file from one of the available locations.
 *
 * @return FSDataInputStream stream of the opened file link
 * @throws IOException on unexpected error, or file not found.
 */
private FSDataInputStream tryOpen() throws IOException {
  for (Path path: fileLink.getLocations()) {
    if (path.equals(currentPath)) continue;
    try {
      in = fs.open(path, bufferSize);
      if (pos != 0) in.seek(pos);
      assert(in.getPos() == pos) : "Link unable to seek to the right position=" + pos;
      if (LOG.isTraceEnabled()) {
        if (currentPath == null) {
          LOG.debug("link open path=" + path);
        } else {
          LOG.trace("link switch from path=" + currentPath + " to path=" + path);
        }
      }
      currentPath = path;
      return(in);
    } catch (FileNotFoundException e) {
      // Try another file location
    }
  }
  throw new FileNotFoundException("Unable to open link: " + fileLink);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:29,代碼來源:FileLink.java

示例8: _decode

import java.io.IOException; //導入依賴的package包/類
private void _decode(AsnInputStream ais, int length) throws MAPParsingComponentException, IOException, AsnException {

        this.gsmSecurityContextData = null;
        this.umtsSecurityContextData = null;

        int tag = ais.getTag();

        if (ais.getTagClass() != Tag.CLASS_CONTEXT_SPECIFIC || ais.isTagPrimitive())
            throw new MAPParsingComponentException("Error while decoding " + _PrimitiveName
                    + ": Primitive has bad tag class or is primitive", MAPParsingComponentExceptionReason.MistypedParameter);

        switch (tag) {
            case _TAG_gsmSecurityContextData:
                this.gsmSecurityContextData = new GSMSecurityContextDataImpl();
                ((GSMSecurityContextDataImpl) this.gsmSecurityContextData).decodeData(ais, length);
                break;
            case _TAG_umtsSecurityContextData:
                this.umtsSecurityContextData = new UMTSSecurityContextDataImpl();
                ((UMTSSecurityContextDataImpl) this.umtsSecurityContextData).decodeData(ais, length);
                break;

            default:
                throw new MAPParsingComponentException("Error while decoding " + _PrimitiveName + ": bad choice tag",
                        MAPParsingComponentExceptionReason.MistypedParameter);
        }
    }
 
開發者ID:RestComm,項目名稱:phone-simulator,代碼行數:27,代碼來源:CurrentSecurityContextImpl.java

示例9: startAM

import java.io.IOException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void startAM() throws YarnException, IOException {
  // application/container configuration
  int heartbeatInterval = conf.getInt(
          SLSConfiguration.AM_HEARTBEAT_INTERVAL_MS,
          SLSConfiguration.AM_HEARTBEAT_INTERVAL_MS_DEFAULT);
  int containerMemoryMB = conf.getInt(SLSConfiguration.CONTAINER_MEMORY_MB,
          SLSConfiguration.CONTAINER_MEMORY_MB_DEFAULT);
  int containerVCores = conf.getInt(SLSConfiguration.CONTAINER_VCORES,
          SLSConfiguration.CONTAINER_VCORES_DEFAULT);
  Resource containerResource =
          BuilderUtils.newResource(containerMemoryMB, containerVCores);

  // application workload
  if (isSLS) {
    startAMFromSLSTraces(containerResource, heartbeatInterval);
  } else {
    startAMFromRumenTraces(containerResource, heartbeatInterval);
  }
  numAMs = amMap.size();
  remainingApps = numAMs;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:SLSRunner.java

示例10: unknownHostEmits

import java.io.IOException; //導入依賴的package包/類
@Test
public void unknownHostEmits() throws IOException, InterruptedException {
  SendsStuff api = Feign.builder()
      .logger(logger)
      .logLevel(logLevel)
      .retryer(new Retryer() {
        @Override
        public void continueOrPropagate(RetryableException e) {
          throw e;
        }
        @Override public Retryer clone() {
            return this;
        }
      })
      .target(SendsStuff.class, "http://robofu.abc");

  thrown.expect(FeignException.class);

  api.login("netflix", "denominator", "password");
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:21,代碼來源:LoggerTest.java

示例11: doGet

import java.io.IOException; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	LOGGER.debug("Finding token to revoke ...");
	String token = req.getParameter("token");
	if (!Preconditions.isEmptyString(token)) {
		try {
			this.service.revokeToken(token);
		} catch (UnrecoverableOAuthException e) {
			OAuthError err = e.getError();
			LOGGER.warn(String.format("Unable to revoke token %s because [%s]%s", token, err.getName(), err.getDescription()));
		}
	} else {
		LOGGER.debug("No token found in parameter, skipping ...");
	}
	this.postSignOut(req, resp);
}
 
開發者ID:sgr-io,項目名稱:social-signin,代碼行數:17,代碼來源:GooglePlusDisconnectServlet.java

示例12: checkIfModifiedSince

import java.io.IOException; //導入依賴的package包/類
/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceInfo File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request 
 * processing is stopped
 */
private boolean checkIfModifiedSince(HttpServletRequest request,
                                     HttpServletResponse response,
                                     ResourceInfo resourceInfo)
    throws IOException {
    try {
        long headerValue = request.getDateHeader("If-Modified-Since");
        long lastModified = resourceInfo.date;
        if (headerValue != -1) {

            // If an If-None-Match header has been specified, if modified since
            // is ignored.
            if ((request.getHeader("If-None-Match") == null) 
                && (lastModified <= headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return false;
            }
        }
    } catch(IllegalArgumentException illegalArgument) {
        return false;
    }
    return true;

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:36,代碼來源:DefaultServlet.java

示例13: onRunStep

import java.io.IOException; //導入依賴的package包/類
@Override
protected void onRunStep() throws SetupStepException {
    try {
        log.d("Ensuring connection to AP");
        workerThreadApConnector.ensureConnectionToSoftAp();

        log.d("Sending connect-ap command");
        ConnectAPCommand.Response response = commandClient.sendCommand(
                // FIXME: is hard-coding zero here correct?  If so, document why
                new ConnectAPCommand(0), ConnectAPCommand.Response.class);
        if (!response.isOK()) {
            throw new SetupStepException("ConnectAPCommand returned non-zero response code: " +
                    response.responseCode);
        }

        commandSent = true;

    } catch (IOException e) {
        throw new SetupStepException(e);
    }
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:22,代碼來源:ConnectDeviceToNetworkStep.java

示例14: parseSoliditySource

import java.io.IOException; //導入依賴的package包/類
private String parseSoliditySource(String includedFile) throws MojoExecutionException {
    try {
        byte[] contract = Files.readAllBytes(Paths.get(soliditySourceFiles.getDirectory(), includedFile));
        CompilerResult result = SolidityCompiler.getInstance(getLog()).compileSrc(
                contract,
                SolidityCompiler.Options.ABI,
                SolidityCompiler.Options.BIN,
                SolidityCompiler.Options.INTERFACE,
                SolidityCompiler.Options.METADATA
        );
        if (result.isFailed()) {
            throw new MojoExecutionException("Could not compile solidity files\n" + result.errors);
        }

        getLog().debug("\t\tResult:\t" + result.output);
        getLog().debug("\t\tError: \t" + result.errors);
        return result.output;
    } catch (IOException ioException) {
        throw new MojoExecutionException("Could not compile files", ioException);
    }
}
 
開發者ID:web3j,項目名稱:web3j-maven-plugin,代碼行數:22,代碼來源:JavaClassGeneratorMojo.java

示例15: process

import java.io.IOException; //導入依賴的package包/類
/**
 * @see SSICommand
 */
@Override
public long process(SSIMediator ssiMediator, String commandName,
        String[] paramNames, String[] paramValues, PrintWriter writer) {
    long lastModified = 0;
    String configErrMsg = ssiMediator.getConfigErrMsg();
    for (int i = 0; i < paramNames.length; i++) {
        String paramName = paramNames[i];
        String paramValue = paramValues[i];
        String substitutedValue = ssiMediator
                .substituteVariables(paramValue);
        try {
            if (paramName.equalsIgnoreCase("file")
                    || paramName.equalsIgnoreCase("virtual")) {
                boolean virtual = paramName.equalsIgnoreCase("virtual");
                lastModified = ssiMediator.getFileLastModified(
                        substitutedValue, virtual);
                Date date = new Date(lastModified);
                String configTimeFmt = ssiMediator.getConfigTimeFmt();
                writer.write(formatDate(date, configTimeFmt));
            } else {
                ssiMediator.log("#flastmod--Invalid attribute: "
                        + paramName);
                writer.write(configErrMsg);
            }
        } catch (IOException e) {
            ssiMediator.log(
                    "#flastmod--Couldn't get last modified for file: "
                            + substitutedValue, e);
            writer.write(configErrMsg);
        }
    }
    return lastModified;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:37,代碼來源:SSIFlastmod.java


注:本文中的java.io.IOException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。