本文整理匯總了Java中java.io.IOException.getStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java IOException.getStackTrace方法的具體用法?Java IOException.getStackTrace怎麽用?Java IOException.getStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.IOException
的用法示例。
在下文中一共展示了IOException.getStackTrace方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextFromFile
import java.io.IOException; //導入方法依賴的package包/類
public static String getTextFromFile(String resourceFile) {
StringBuilder sb = new StringBuilder();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(classloader.getResourceAsStream(resourceFile), StandardCharsets.UTF_8));) {
reader.lines().forEach(line -> sb.append(line));
} catch (IOException e) {
throw new RuntimeException("Cannot read file with JSON " + e.getStackTrace());
}
return sb.toString();
}
示例2: getTextFromFile
import java.io.IOException; //導入方法依賴的package包/類
public static String getTextFromFile(String responseFile) {
StringBuilder sb = new StringBuilder();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(classloader.getResourceAsStream("test.csv")))) {
reader.lines().forEach(line -> sb.append(line));
} catch (IOException e) {
throw new RuntimeException("Cannot read file with JSON response " + e.getStackTrace());
}
return sb.toString();
}
示例3: setBinaryStream
import java.io.IOException; //導入方法依賴的package包/類
/**
* 以指定指定長度將二進製流寫入OutputStream,並返回OutputStream
*
* @param pos
* pos
* @return OutputStream
* @throws SQLException
* SQLException
*/
public OutputStream setBinaryStream(long pos) throws SQLException {
// 暫不支持
nonsupport();
pos--;
if (pos < 0) {
throw new SQLException("pos < 0");
}
if (pos > _length) {
throw new SQLException("pos > length");
}
// 將byte[]轉為ByteArrayInputStream
ByteArrayInputStream inputStream = new ByteArrayInputStream(_bytes);
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] bytes = new byte[(int) pos];
try {
bytes = new byte[inputStream.available()];
int read;
while ((read = inputStream.read(bytes)) >= 0) {
os.write(bytes, 0, read);
}
} catch (IOException e) {
e.getStackTrace();
}
// 返回OutputStream
return (OutputStream) os;
}
示例4: Settings
import java.io.IOException; //導入方法依賴的package包/類
/**
* constructor.
*/
public Settings() {
ClassLoader loader = Settings.class.getClassLoader();
try (InputStream is = loader.getResourceAsStream("app.properties")) {
this.load(is);
} catch (IOException ioe) {
ioe.getStackTrace();
}
}
示例5: Bot
import java.io.IOException; //導入方法依賴的package包/類
/**
* constructor.
* @param answersPath - answersPath
* @throws IOException - IOException
*/
public Bot(String answersPath) throws IOException {
try {
this.botAnswers = Files.readAllLines(Paths.get(answersPath), StandardCharsets.UTF_8);
} catch (IOException ioe) {
ioe.getStackTrace();
}
}
示例6: testReadWithCorruptPadding
import java.io.IOException; //導入方法依賴的package包/類
/**
* corrupt the padding by inserting non-zero bytes. Make sure the reader
* throws exception.
*/
@Test
public void testReadWithCorruptPadding() throws IOException {
final RaftStorage storage = new RaftStorage(storageDir, StartupOption.REGULAR);
File openSegment = storage.getStorageDir().getOpenLogFile(0);
LogEntryProto[] entries = new LogEntryProto[10];
LogOutputStream out = new LogOutputStream(openSegment, false,
16 * 1024 * 1024, 4 * 1024 * 1024, bufferSize);
for (int i = 0; i < 10; i++) {
SimpleOperation m = new SimpleOperation("m" + i);
entries[i] = ProtoUtils.toLogEntryProto(m.getLogEntryContent(), 0, i,
clientId, callId);
out.write(entries[i]);
}
out.flush();
// make sure the file contains padding
Assert.assertEquals(4 * 1024 * 1024, openSegment.length());
try (FileOutputStream fout = new FileOutputStream(openSegment, true)) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[]{-1, 1});
fout.getChannel()
.write(byteBuffer, 16 * 1024 * 1024 - 10);
}
List<LogEntryProto> list = new ArrayList<>();
try (LogInputStream in = new LogInputStream(openSegment, 0,
RaftServerConstants.INVALID_LOG_INDEX, true)) {
LogEntryProto entry;
while ((entry = in.nextEntry()) != null) {
list.add(entry);
}
Assert.fail("should fail since we corrupt the padding");
} catch (IOException e) {
boolean findVerifyTerminator = false;
for (StackTraceElement s : e.getStackTrace()) {
if (s.getMethodName().equals("verifyTerminator")) {
findVerifyTerminator = true;
break;
}
}
Assert.assertTrue(findVerifyTerminator);
}
Assert.assertArrayEquals(entries,
list.toArray(new LogEntryProto[list.size()]));
}