MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / openAsRawString

Method openAsRawString

ij/src/main/java/ij/macro/Functions.java:4708–4747  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4706 }
4707
4708 String openAsRawString() {
4709 long max = 5000;
4710 String path = getFirstString();
4711 boolean specifiedMax = false;
4712 if (interp.nextToken()==',') {
4713 max = (long)getNextArg();
4714 specifiedMax = true;
4715 }
4716 interp.getRightParen();
4717 if (path.equals("")) {
4718 OpenDialog od = new OpenDialog("Open As String", "");
4719 String directory = od.getDirectory();
4720 String name = od.getFileName();
4721 if (name==null) return "";
4722 path = directory + name;
4723 }
4724 String str = "";
4725 File file = new File(path);
4726 if (!file.exists())
4727 interp.error("File not found");
4728 try {
4729 StringBuffer sb = new StringBuffer(5000);
4730 long len = file.length();
4731 if (max>len || (path.endsWith(".txt")&&!specifiedMax))
4732 max = len;
4733 InputStream in = new BufferedInputStream(new FileInputStream(path));
4734 DataInputStream dis = new DataInputStream(in);
4735 byte[] buffer = new byte[(int)max];
4736 dis.readFully(buffer);
4737 dis.close();
4738 char[] buffer2 = new char[buffer.length];
4739 for (int i=0; i<buffer.length; i++)
4740 buffer2[i] = (char)(buffer[i]&255);
4741 str = new String(buffer2);
4742 }
4743 catch (Exception e) {
4744 interp.error("File open error \n\""+e.getMessage()+"\"\n");
4745 }
4746 return str;
4747 }
4748
4749 String closeFile() {
4750 String f = getStringArg();

Callers 1

doFileMethod · 0.95

Calls 13

getFirstStringMethod · 0.95
getNextArgMethod · 0.95
getDirectoryMethod · 0.95
getFileNameMethod · 0.95
getRightParenMethod · 0.80
lengthMethod · 0.65
readFullyMethod · 0.65
closeMethod · 0.65
nextTokenMethod · 0.45
equalsMethod · 0.45
existsMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected