java.io.IOError Java Examples

The following examples show how to use java.io.IOError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JrtPath.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public final URI toUri() {
    try {
        String p = toAbsolutePath().path;
        if (!p.startsWith("/modules") || p.contains("..")) {
            throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
        }

        p = p.substring("/modules".length());
        if (p.isEmpty()) {
            p = "/";
        }
        return new URI("jrt", p, null);
    } catch (URISyntaxException ex) {
        throw new AssertionError(ex);
    }
}
 
Example #2
Source File: Command.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
final protected Path getJFRInputFile(Deque<String> options) throws UserSyntaxException, UserDataException {
    if (options.isEmpty()) {
        throw new UserSyntaxException("missing file");
    }
    String file = options.removeLast();
    if (file.startsWith("--")) {
        throw new UserSyntaxException("missing file");
    }
    try {
        Path path = Paths.get(file).toAbsolutePath();
        ensureAccess(path);
        ensureJFRFile(path);
        return path;
    } catch (IOError ioe) {
        throw new UserDataException("i/o error reading file '" + file + "', " + ioe.getMessage());
    } catch (InvalidPathException ipe) {
        throw new UserDataException("invalid path '" + file + "'");
    }
}
 
Example #3
Source File: Command.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
final protected Path getJFRInputFile(Deque<String> options) throws UserSyntaxException, UserDataException {
    if (options.isEmpty()) {
        throw new UserSyntaxException("missing file");
    }
    String file = options.removeLast();
    if (file.startsWith("--")) {
        throw new UserSyntaxException("missing file");
    }
    try {
        Path path = Paths.get(file).toAbsolutePath();
        ensureAccess(path);
        ensureJFRFile(path);
        return path;
    } catch (IOError ioe) {
        throw new UserDataException("i/o error reading file '" + file + "', " + ioe.getMessage());
    } catch (InvalidPathException ipe) {
        throw new UserDataException("invalid path '" + file + "'");
    }
}
 
Example #4
Source File: RollupSerializationHelper.java    From blueflood with Apache License 2.0 6 votes vote down vote up
public static ObjectNode rollupToJson(Rollup rollup) {
    if (rollup instanceof BluefloodCounterRollup)
        return handleCounterRollup((BluefloodCounterRollup)rollup);
    else if (rollup instanceof BluefloodTimerRollup)
        return handleTimerRollup((BluefloodTimerRollup)rollup);
    else if (rollup instanceof BluefloodSetRollup)
        return handleSetRollup((BluefloodSetRollup)rollup);
    else if (rollup instanceof BluefloodGaugeRollup)
        return handleGaugeRollup((BluefloodGaugeRollup)rollup);
    else if (rollup instanceof BasicRollup)
        return handleBasicRollup((BasicRollup)rollup, JsonNodeFactory.instance.objectNode());
    else {
        log.error("Error encountered while serializing the rollup "+rollup);
        throw new IOError(new IOException("Cannot serialize the Rollup : "+rollup));
    }
}
 
Example #5
Source File: KeycloakPropertiesConfigSource.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> readProperties(final InputStream is) {
    if (is == null) {
        return Collections.emptyMap();
    }
    try (Closeable ignored = is) {
        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
            try (BufferedReader br = new BufferedReader(isr)) {
                final Properties properties = new Properties();
                properties.load(br);
                return transform((Map<String, String>) (Map) properties);
            }
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #6
Source File: ExceptionUtilTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private Throwable generateException() {
    try {
        try {
            Integer.parseInt("23.23232");
        } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException("Incorrect param", nfe);
        }
    } catch (IllegalArgumentException iae) {
        try {
            throw new IOException("Request processing failed", iae);
        } catch (IOException e) {
            try {
                throw new IOError(e);
            } catch (IOError ie) {
                return new RuntimeException("Unexpected exception", ie);
            }
        }
    }
    throw new RuntimeException("Should not reach here");
}
 
Example #7
Source File: DesugarMethodAttribute.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
protected Attribute read(
    ClassReader classReader,
    int offset,
    int length,
    char[] charBuffer,
    int codeAttributeOffset,
    Label[] labels) {
  byte[] classAttrBytes = new byte[length];
  for (int i = 0; i < length; i++) {
    classAttrBytes[i] = (byte) classReader.readByte(i + offset);
  }
  try {
    return new DesugarMethodAttribute(
        DesugarMethodInfo.parseFrom(classAttrBytes, ExtensionRegistryLite.getEmptyRegistry()));
  } catch (InvalidProtocolBufferException e) {
    throw new IOError(e);
  }
}
 
Example #8
Source File: InputFileProvider.java    From bazel with Apache License 2.0 6 votes vote down vote up
default ImmutableList<FileContentProvider<? extends InputStream>> toInputFileStreams() {
  ImmutableList.Builder<FileContentProvider<? extends InputStream>> inputClassFileContents =
      ImmutableList.builder();
  for (String inputFileName : this) {
    inputClassFileContents.add(
        new FileContentProvider<>(
            inputFileName,
            () -> {
              try {
                return getInputStream(inputFileName);
              } catch (IOException e) {
                throw new IOError(e);
              }
            }));
  }
  return inputClassFileContents.build();
}
 
Example #9
Source File: StressProfile.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static StressProfile load(URI file) throws IOError
{
    try
    {
        Constructor constructor = new Constructor(StressYaml.class);

        Yaml yaml = new Yaml(constructor);

        InputStream yamlStream = file.toURL().openStream();

        if (yamlStream.available() == 0)
            throw new IOException("Unable to load yaml file from: "+file);

        StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);

        StressProfile profile = new StressProfile();
        profile.init(profileYaml);

        return profile;
    }
    catch (YAMLException | IOException | RequestValidationException e)
    {
        throw new IOError(e);
    }
}
 
Example #10
Source File: DirectoryInputFileProvider.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<String> iterator() {
  final List<String> entries = new ArrayList<>();
  try (Stream<Path> paths = Files.walk(root)) {
    paths.forEach(
        new Consumer<Path>() {
          @Override
          public void accept(Path t) {
            if (Files.isRegularFile(t)) {
              // Internally, we use '/' as a common package separator in filename to abstract
              // that filename can comes from a zip or a directory.
              entries.add(root.relativize(t).toString().replace(File.separatorChar, '/'));
            }
          }
        });
  } catch (IOException e) {
    throw new IOError(e);
  }
  return entries.iterator();
}
 
Example #11
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown()
{
    if (titanGraph == null)
    {
        return;
    }
    try
    {
        titanGraph.shutdown();
    }
    catch (IOError e)
    {
        // TODO Fix issue in shutting down titan-cassandra-embedded
        System.err.println("Failed to shutdown titan graph: " + e.getMessage());
    }

    titanGraph = null;
}
 
Example #12
Source File: ApplicationPropertiesConfigSource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> readProperties(final InputStream is) {
    if (is == null) {
        return Collections.emptyMap();
    }
    try (Closeable ignored = is) {
        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
            try (BufferedReader br = new BufferedReader(isr)) {
                final Properties properties = new Properties();
                properties.load(br);
                return (Map<String, String>) (Map) properties;
            }
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #13
Source File: Volume.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected ByteBuffer makeNewBuffer(long offset) {
    try {
        long newBufSize =  offset% BUF_SIZE;
        newBufSize = newBufSize + newBufSize%BUF_SIZE_INC; //round to BUF_SIZE_INC
        return fileChannel.map(
                mapMode,
                offset - offset% BUF_SIZE, newBufSize );
    } catch (IOException e) {
        if(e.getCause()!=null && e.getCause() instanceof OutOfMemoryError){
            throw new RuntimeException("File could not be mapped to memory, common problem on 32bit JVM. Use `DBMaker.newRandomAccessFileDB()` as workaround",e);
        }

        throw new IOError(e);
    }
}
 
Example #14
Source File: Volume.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void close() {
    growLock.lock();
    try{
        fileChannel.close();
        raf.close();
        if(!readOnly)
            sync();
        for(ByteBuffer b:buffers){
            if(b!=null && (b instanceof MappedByteBuffer)){
                unmap((MappedByteBuffer) b);
            }
        }
        buffers = null;
    } catch (IOException e) {
        throw new IOError(e);
    }finally{
        growLock.unlock();
    }

}
 
Example #15
Source File: DBMaker.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates new database in temporary folder.
 *
 * @return
 */
public static DBMaker newTempFileDB() {
    try {
        return newFileDB(File.createTempFile("mapdb-temp","db"));
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #16
Source File: LayoutPullParser.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public LayoutPullParser(InputStream layoutFileStream, ResourceNamespace appNamespace) {
    this.appNamespace = appNamespace;
    if (layoutFileStream == null) {
        throw new NullPointerException("LayoutStream is null");
    }
    try {
        init(layoutFileStream);
    } catch (XmlPullParserException e) {
        throw new IOError(e);
    }
}
 
Example #17
Source File: EngineWrapper.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private int checksum(){
    try {
        DataOutput2 out = new DataOutput2();
        serializer.serialize(out, item);
        byte[] bb = out.copyBytes();
        return Arrays.hashCode(bb);
    }catch(IOException e){
        throw new IOError(e);
    }
}
 
Example #18
Source File: Zip.java    From turbine with Apache License 2.0 5 votes vote down vote up
public String string(ByteBuffer buf, int offset, int length) {
  buf = buf.duplicate();
  buf.position(offset);
  buf.limit(offset + length);
  decoder.reset();
  try {
    return decoder.decode(buf).toString();
  } catch (CharacterCodingException e) {
    throw new IOError(e);
  }
}
 
Example #19
Source File: PlainTextWikipediaPageWriter.java    From wikiforia with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Default constructor
 * @param output which file to write to
 */
public PlainTextWikipediaPageWriter(File output) {
    try {
        this.output = output;
        this.fileChannel = FileChannel.open(Paths.get(output.toURI()), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #20
Source File: JLineConsole.java    From es6draft with MIT License 5 votes vote down vote up
@Override
public String readLine() {
    try {
        return console.readLine("");
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #21
Source File: JavacTurbineTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  try {
    processingEnv
        .getFiler()
        .getResource(StandardLocation.CLASS_OUTPUT, "", "NO_SUCH_FILE")
        .openInputStream();
  } catch (IOException e) {
    throw new IOError(e);
  }
  return false;
}
 
Example #22
Source File: ModuleReferences.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<URI> find(String name) throws IOException {
    ensureOpen();
    Path path = Resources.toFilePath(dir, name);
    if (path != null) {
        try {
            return Optional.of(path.toUri());
        } catch (IOError e) {
            throw (IOException) e.getCause();
        }
    } else {
        return Optional.empty();
    }
}
 
Example #23
Source File: FileContentProvider.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void sink(OutputFileProvider outputFileProvider) {
  try (S input = get()) {
    outputFileProvider.write(getBinaryPathName(), ByteStreams.toByteArray(input));
  } catch (IOException e) {
    throw new IOError(e);
  }
}
 
Example #24
Source File: AbstractPosixTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public Attributes getAttributes() {
    try {
        return pty.getAttr();
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #25
Source File: DataIntegrityMetadata.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void writeChunkSize(int length)
{
    try
    {
        incrementalOut.writeInt(length);
    }
    catch (IOException e)
    {
        throw new IOError(e);
    }
}
 
Example #26
Source File: AbstractPosixTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public void setAttributes(Attributes attr) {
    try {
        pty.setAttr(attr);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #27
Source File: VolumeTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void read_beyond_end_mapped_long(){
    try{
        Volume v = new Volume.MappedFileVol(Utils.tempDbFile(), false);
        v.getLong(1000000);
        fail();
    }catch(IOError e){
        assertTrue(e.getCause() instanceof  EOFException);
    }
}
 
Example #28
Source File: AbstractDocumentationMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies a class loader that is able to read the classes from the Maven class path.
 *
 * @param parent the parent class loader.
 * @param classPath the additional class path.
 * @param size the size of the class path.
 * @return the class loader.
 */
private ClassLoader getProjectClassLoader(ClassLoader parent, Iterable<File> classPath, int size) {
	try {
		final URL[] urls = new URL[size];
		int i = 0;
		for (final File localFile : classPath) {
			urls[i] = localFile.toURI().toURL();
			++i;
		}
		return new URLClassLoader(urls, getClass().getClassLoader());
	} catch (IOException exception) {
		throw new IOError(exception);
	}
}
 
Example #29
Source File: JavaConsole.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String readLine(String fmt, Object... args) throws IOError {
    if (hasConsole()) {
        return theConsole.readLine(fmt, args);
    } else {
        throw ROOT_LOGGER.noConsoleAvailable();
    }
}
 
Example #30
Source File: RemoveUnusedImports.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
private static JCCompilationUnit parse(Context context, String javaInput)
    throws FormatterException {
  DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
  context.put(DiagnosticListener.class, diagnostics);
  Options.instance(context).put("--enable-preview", "true");
  Options.instance(context).put("allowStringFolding", "false");
  JCCompilationUnit unit;
  JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
  try {
    fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of());
  } catch (IOException e) {
    // impossible
    throw new IOError(e);
  }
  SimpleJavaFileObject source =
      new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
          return javaInput;
        }
      };
  Log.instance(context).useSource(source);
  ParserFactory parserFactory = ParserFactory.instance(context);
  JavacParser parser =
      parserFactory.newParser(
          javaInput, /*keepDocComments=*/ true, /*keepEndPos=*/ true, /*keepLineMap=*/ true);
  unit = parser.parseCompilationUnit();
  unit.sourcefile = source;
  Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics =
      Iterables.filter(diagnostics.getDiagnostics(), Formatter::errorDiagnostic);
  if (!Iterables.isEmpty(errorDiagnostics)) {
    // error handling is done during formatting
    throw FormatterException.fromJavacDiagnostics(errorDiagnostics);
  }
  return unit;
}