Hmm..is there an cleaner way of doing this?
is there any way to modify this code so that it keeps asking the user for the file name, until the user gives the correct file name ("address.txt")? any help is appreciated
StringTokenizer tokenizer; // declare tokenizer
String inData; // declare inData
ExtPerson person; // person
try //try statement
System.out.print("Enter file name: "); // prompt user for file name
inData = keyboard.readLine(); // read user input
BufferedReader inFile = new BufferedReader(new FileReader(inData));
String input = inFile.readLine(); // read line from text
do // begin do-while loop, while its not end of file, read rest of file
tokenizer = new StringTokenizer(input);
fName = tokenizer.nextToken(); // read first name
lName = tokenizer.nextToken(); // read last name
input = inFile.readLine(); //read line
tokenizer = new StringTokenizer(input);
month = Integer.parseInt(tokenizer.nextToken()); // read month
day = Integer.parseInt(tokenizer.nextToken()); // read day
year = Integer.parseInt(tokenizer.nextToken()); // read year
sAddress = inFile.readLine(); // read street address
c = inFile.readLine(); // read city
s = inFile.readLine(); // read state
z = inFile.readLine(); // read zip
pNumber = inFile.readLine(); // read phone number
pStatus = inFile.readLine(); // read person status
input = inFile.readLine(); //read line
// calls ExtPerson and puts data in ExtPerson contructor
person = new ExtPerson(fName, lName, month, day, year, sAddress, c, s, z, pNumber, pStatus);
// uses insertLast and puts data in adBook
adBook.insertLast(person);
}while (input != null); //end of do-while
} // end try
catch(FileNotFoundException e) // catch, if wrong file is entered, display messages
System.out.println(e.getMessage()); // default invalid file message
System.out.println("Please enter another file name. "); // prompt directions
System.out.print("Enter file name: "); // prompt user for file name
inData = keyboard.readLine(); // read user input
BufferedReader inFile = new BufferedReader(new FileReader(inData));
String input = inFile.readLine(); // read line from text
do // begin do-while loop, while its not end of file, read rest of file
tokenizer = new StringTokenizer(input);
fName = tokenizer.nextToken(); // read first name
lName = tokenizer.nextToken(); // read last name
input = inFile.readLine(); //read line
tokenizer = new StringTokenizer(input);
month = Integer.parseInt(tokenizer.nextToken()); // read month
day = Integer.parseInt(tokenizer.nextToken()); // read day
year = Integer.parseInt(tokenizer.nextToken()); // read year
sAddress = inFile.readLine(); // read street address
c = inFile.readLine(); // read city
s = inFile.readLine(); // read state
z = inFile.readLine(); // read zip
pNumber = inFile.readLine(); // read phone number
pStatus = inFile.readLine(); // read person status
input = inFile.readLine(); //read line
// calls ExtPerson and puts data in ExtPerson contructor
person = new ExtPerson(fName, lName, month, day, year, sAddress, c, s, z, pNumber, pStatus);
// uses insertLast and puts data in adBook
adBook.insertLast(person);
}while (input != null); //end of do-while
} // end catch
} // end loadAddressBook method
Reply on http://forum.java.sun.com/thread.jspa?threadID=714603 this is a crosspost
Similar Messages
-
I have two apple accounts and one of which has my music on. I would like to move this music to the other account. Is there a simple way of doing this?
There is currently no way to merge accounts. The best option is to pick one, and use it consistantly.
HTH. -
I would like to duplicate the folders and apps that I have set up on my iPhone to my iPad. Is there a quick way of doing this without going through the whole process again manually?
You can restore your iPad with your iPhone backup but items that are iPhone only will not transfer. It should recreate all your folders. It can't hurt anything to try.
-
Is there a better way of doing this? (multifileupload/forms/mysql)
Hi all.
I've managed to cobble together a page that will let me upload three files paths and three text boxes to a mysql database. the the files also go to specific directories depending on conditions.
what im looking for is to see if there is a more efficient way of doing this. im mainly looking at the value and name strings along with the preparedstatement insert. i'd like to see if i can make it more dynamic so i don't have to predefine an amount anywhere.
This code is working as is if anyone wants to use it in it's current state.
here is the form
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
<TITLE>File Upload Page</TITLE>
</HEAD>
<BODY>Upload Files
<FORM name="filesForm" action="uploadTestProccess.jsp" method="POST" enctype="multipart/form-data">
File 1:<input type="file" name="file1"/><br/>
File 2:<input type="file" name="file2"/><br/>
File 3:<input type="file" name="file3"/><br/>
text4: <input type="text" name="textField4" value="this is a test4"><br>
text5: <input type="text" name="textField5" value="this is a test5"><br>
text6: <input type="text" name="textField6" value="this is a test6"><br>
<input type="submit" name="submit" value="Upload Files"/>
</FORM>
</BODY>
</HTML>and here is the insert
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>
<%@ page import="java.sql.*"%>
<%!
String value4;
String value5;
String value6;
String name1;
String name2;
String name3;
String dir;
Connection dbconn;
ResultSet result;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<%
//System.out.println("Content Type ="+request.getContentType());
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(10000000);
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
for(int i=1; itr.hasNext(); i++){
FileItem fi = (FileItem)itr.next();
//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if(!fi.isFormField()) {
out.print(i);
//out.println("\nNAME: "+fi.getName());
//out.println("SIZE: "+fi.getSize());
if(i==1){
name1 = fi.getName();
dir = "file1/";
} else if (i==2){
name2 = fi.getName();
dir = "file2/";
} else {
name3 = fi.getName();
dir = "file3/";
File fNew= new File(application.getRealPath("examples1/" + dir), fi.getName());
//out.println(fNew.getAbsolutePath());
fi.write(fNew);
out.print("success<br>" + fi.getName() + "<br>");
} else {
//gets field names and values
// out.println("Field ="+fi.getFieldName());
String name = fi.getFieldName();
if(i==4){
value4 = fi.getString();
} else if (i==5){
value5 = fi.getString();
} else if (i==6) {
value6 = fi.getString();
String value = fi.getString();
out.println("Found field with name <b>"+ name +"</b> and value <b>"+ value +"</b><br>");
Class.forName("org.gjt.mm.mysql.Driver");
dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx?user=root&password=xxx");
PreparedStatement sql = dbconn.prepareStatement("INSERT INTO uploadtest (file1, file2, file3, four, five, six) VALUES (?,?,?,?,?,?)");
sql.setString(1, name1);
sql.setString(2, name2);
sql.setString(3, name3);
sql.setString(4, value4);
sql.setString(5, value5);
sql.setString(6, value6);
int result = sql.executeUpdate();
%>
<body>
<!--Upload Successful!!-->
</body>
</html>anyone?
-
Why can't you print a cd jewel case listing of songs using iTunes. Is there some other way to do this without using iTunes?
Hi spider1950,
As long as you have the most recent update of iTunes (11.0.4), you should be able to print a jewel case insert directly from iTunes. You may find the following page useful:
Apple Support: Print CD Inserts
https://www.apple.com/findouthow/music/itunes.html#makecd-printinserts
Regards,
- Brenden -
I want to print from my iPad in my truck. Is there an easy way of doing this?
I want to print from my iPad from inside my truck. Is there an easy way to do this?
The bluetooth is generally meant for keyboards and speakers, no idea if it'd work with a printer.
I suppose you could shop for printers and look to see if one specifically mentions compantibility with iPads.
The iPad was created to be a consumption device. Used to consume data, watch movies, read books, listen to music. functionality like what you're wanting is beyond how the device was originally conceived, so it requires tweaking and fixing.
There are other devices out there that have more functionality, including some that might hardwire to a printer. The easy part would be power for the printer. A $25 inverter will give you that in your vehicle. -
I don't want to write too much code is there a different way of doing this
I am writing a precedure to check on the max test scores for different codes ('S01','S02'.S03') --there are more
then I need to insert the table if the record with the best score does not exists for example for b.sortest_tesc_code = 'BSV', I am writing a cursor
for each code (.sortest_tesc_code = 'S01') is there a way to do this different? so I cant do something like a.sortest_tesc_code in ('S01','S02'.S03') and store in a
variable then insert, the problem is that you can have a student that have only one test other that have two etc..etc.. is not consistent, also If the b.sortest_tesc_code = 'BSV') is already in the table I don't do an insert I will have to do an update if the sortest_test_score is greater since the student can submit scores more than once... In another words check if the record exists( b.sortest_tesc_code = 'BSV') if is there compare with the new max score and if the new max score is greater then update.. If the score (by code) is not in the table insert
Hope this is clear, this is what I have, I now it will work but it will be too much code..check for exists and not exists in two different precedures..
Thank you
CURSOR get_the_max_scores_S01_cur IS
SELECT
sortest_pidm, a.sortest_test_score, a.sortest_tesc_code,
a.sortest_test_date,a.sortest_equiv_ind
FROM
saturn.spriden, saturn.sortest a, saturn.stvtesc
WHERE
a.sortest_pidm = spriden_pidm
AND stvtesc_code = a.sortest_tesc_code
AND spriden_change_ind IS NULL
-----and a.sortest_tesc_code in ('S01','S02'.S03')
AND a.sortest_tesc_code = 'S01'
--and spriden_id = p_student_id --
---for test purposes
AND sortest_pidm = 133999 ----THE WILL BE A PARAMETER
AND a.sortest_test_score =
(SELECT MAX (b.sortest_test_score)
FROM saturn.sortest b
WHERE a.sortest_tesc_code = b.sortest_tesc_code
AND a.sortest_pidm = b.sortest_pidm)
AND NOT EXISTS
(SELECT 1 FROM saturn.sortest b
WHERE A.sortest_tesc_code = b.sortest_tesc_code
AND a.sortest_pidm = b.sortest_pidm
and b.sortest_tesc_code = 'BSV');
BEGIN
UTL_FILE.fclose_all;
v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'a');
UTL_FILE.put_line (v_file_handle,
CHR (10) || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
UTL_FILE.put_line (v_file_handle, 'sortest_best_sct_scorest');
--check for an open cursor before opening
IF get_the_max_scores_S01_cur%ISOPEN
THEN
CLOSE get_the_max_scores_S01_cur;
END IF;
OPEN get_the_max_scores_S01_cur;
LOOP
FETCH get_the_max_scores_S01_cur
INTO v_pidm, v_tscore, v_testcode,
v_test_date, v_equiv_ind;
EXIT WHEN get_the_max_scores_S01_cur%NOTFOUND;
IF get_the_max_scores_S01_cur%FOUND
THEN
INSERT INTO saturn.sortest
(sortest_pidm,sortest_tesc_code,sortest_test_date,sortest_test_score,
sortest_activity_date,sortest_equiv_ind,sortest_user_id,sortest_data_origin)
VALUES
v_pidm,
'BSV',
v_test_date,
v_tscore,
sysdate,
v_equiv_ind,
p_user,
'best_test_scores process'
END IF;
END LOOP;
COMMIT;
---Initialize variables
v_pidm := NULL;
v_test_date := NULL;
v_tscore := NULL;
v_equiv_ind := NULL;
v_testcode := NULL;
CLOSE get_the_max_scores_S01_cur;
----then another do the same for S02...S03Thank you, here is the code, I change the name of the tables, but it is the same concept.what I need is to extract the max score for each code (s01,s02,s03,s04)
then insert a record with a different code in the same table
BSM Best Math SAT (S01)
BSW Best writing SAT (S04)
BSC Best READING SAT (S03)
BSE Best READING SAT (S02)
I need to be able to check if the BS codes are already in the table (BSM...BSC..) IF they are not do an insert and if they are do an update get the maximun score
again (the students can submit more than one score form the same code and any date) and if the maximun is different(greater) of what is already in the database (with the BSM...BSC.. codes) do an update, IF NOT if is the same or less don't update...
I need the PERSON table because I need to use the ID as a parameter they (user) can run the process for one ID or all the records in the table TEST
Thank you, I hope is clear
create table TEST
TEST_PIDM NUMBER(8) NOT NULL,
TEST_TESC_CODE VARCHAR2(4 CHAR) NOT NULL,
TEST_TEST_DATE DATE NOT NULL,
TEST_TEST_SCORE VARCHAR2(5 CHAR) NOT NULL,
TEST_ACTIVITY_DATE DATE NOT NULL,
TEST_EQUIV_IND VARCHAR2(1 CHAR) NOT NULL
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'EB' ,TO_DATE( '01-JUN-2004', 'DD-MON-YYYY'),'710',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'M2' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'710',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S01' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'750',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S01' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'720',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S02' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S02' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'730',SYSDATE,'N'
FROM DUAL ;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S03' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'780',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S03' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S04' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'770',SYSDATE,'N'
FROM DUAL;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S04' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL;
CREATE TABLE PERSON
PERSON_PIDM NUMBER(8) NOT NULL,
PERSON_ID VARCHAR2(9 CHAR) NOT NULL
INSERT INTO PERSON
( PERSON_PIDM , PERSON_ID)
SELECT
128019,'003334556'
FROM DUAL ;
CREATE TABLE VALTSC
VALTSC_CODE VARCHAR2(4 CHAR) NOT NULL,
VALTSC_DESC VARCHAR2(30 CHAR)
INSERT INTO VALTSC
VALTSC_CODE,
VALTSC_DESC
SELECT
'S01' ,
'XXS01'
FROM DUAL;
INSERT INTO VALTSC
VALTSC_CODE,
VALTSC_DESC
SELECT
'S02' ,
'XXS02'
FROM DUAL
INSERT INTO VALTSC
VALTSC_CODE,
VALTSC_DESC
SELECT
'S03' ,
'XXS03'
FROM DUAL;
INSERT INTO VALTSC
VALTSC_CODE,
VALTSC_DESC
SELECT
'S04' ,
'XXS04'
FROM DUAL; -
Is there a better way of doing this?
Finally managed to get navigation to work the way I want!!!
But not being an expert at Oracle PL/SQL i'm sure this code could be written a better way.
I'm currently looping through the sublinks twice, first time to get a count second time to display the actual links. the reason for this is the bottom link needs a different style. Anyway here is the code I am using:
<oracle>
declare
x number;
y number;
begin
x := 0;
y := 0;
for c1 in (
select id, display_name, name
from #owner#.WWSBR_ALL_FOLDERS
where parent_id = #PAGE.PAGEID# and caid=1917 and DISPLAY_IN_PARENT_FOLDER = 1
order by display_name
loop
x := x+1;
end loop;
htp.p('<tr><td id="sidenavtop"><strong>#TITLE#</strong></td></tr>');
for c1 in (
select id, display_name, name
from #owner#.WWSBR_ALL_FOLDERS
where parent_id = #PAGE.PAGEID# and caid=1917 and DISPLAY_IN_PARENT_FOLDER = 1
order by display_name
loop
y := y+1;
if x = y then
htp.p('<TR><TD id="sidenavbottom">'||c1.display_name||'</TD></TR>');
else
htp.p('<TR><TD id="sidenavitem">'||c1.display_name||'</TD></TR>');
end if;
end loop;
end;
</oracle>Well, you could fetch the count into a local variable, e.g.
SELECT count(*)
INTO x
FROM ...
WHERE ...;
and move on, but then you are doing two fetches. I'm really sleepy at the moment, so it's possible this is logically and syntactically fouled up, but another option may be:
DECLARE
CURSOR c1 IS
select id, display_name, name
from #owner#.WWSBR_ALL_FOLDERS
where parent_id = #PAGE.PAGEID# and caid=1917 and DISPLAY_IN_PARENT_FOLDER = 1
order by display_name;
r1 c1%ROWTYPE;
l_display_name wwsbr_all_folders.display_name%TYPE;
BEGIN
htp.p('<tr><td id="sidenavtop">#TITLE#</td></tr>');
OPEN c1;
FETCH c1 INTO r1;
l_display_name := r1.display_name;
--hang on to the display name
WHILE c1%FOUND LOOP
FETCH c1 INTO r1;
--see if there's another row...
IF c1%FOUND THEN
--if so, ouput the current value of l_display_name as sidenavitem
htp.p('<TR><TD id="sidenavitem">'|| l_display_name||'</TD></TR>');
l_display_name := r1.display_name;
ELSE
--if not, output the current value of l_display_name as sidenavbottom
htp.p('<TR><TD id="sidenavbottom">'|| l_display_name||'</TD></TR>');
END IF;
END LOOP;
CLOSE c1;
end;
Hope this helps!
-John
Message was edited by:
John Hopkins -
Hello everyone,
So I'm going to blurt out two classes of code. First is a plain entity bean and the second is a helper class with two static methods to help me to convert Object into byte[] and vice versa without much worrying.
Now the problem is, how to persist this entity bean and it's two Objects (two Lists) in a more "J2EE5 way". I just need to store these two Objects, or any Serializable Object, into persistent storage. So how to avoid this serialization by-hand that I'm doing... ?
Thank you for your interest - and help :),
Samuli
Maybe using a @Lob notation or such? I've tried, but I can't get it workign. @Lob itself is not enough since it results in casting problems when retrieveing the data back from the persistent storage.
And oh, I'm just using the simple CMP with this.. EJB using EntityManager's persist method to store and so on..
EntityBean class (imports and packages excluded)
@Entity
public class MessageHandlerChain implements java.io.Serializable {
@TableGenerator(
name="messageHandlerChainIDGenerator",
allocationSize=1,
initialValue=1
@GeneratedValue(
generator="messageHandlerChainIDGenerator",
strategy=GenerationType.TABLE
@Id
private Integer messageHandlerChainID;
@Lob
private byte[] messageHandlers;
@Lob
private byte[] messageHandlerProperties;
@Transient
private List<String> messageHandlersObj = new ArrayList<String>();
@Transient
private List<Map<String,String>> messageHandlerPropertiesObj = new ArrayList<Map<String,String>>();
* Constructs an empty instance of <code>MessageHandlerChain</code> without any properties.
public MessageHandlerChain() {
public Integer getMessageHandlerChainID() {
return messageHandlerChainID;
public void setMessageHandlerChainID(Integer messageHandlerChainID) {
this.messageHandlerChainID = messageHandlerChainID;
public List<String> getMessageHandlers() {
return messageHandlersObj;
public void setMessageHandlers(List<String> messageHandlersObj) {
if (messageHandlersObj == null) {
System.out.println("[MessageHandlerChain] setMessageHandlers() can't be given a null value.");
return;
this.messageHandlersObj = messageHandlersObj;
public List<Map<String,String>> getMessageHandlerProperties() {
return messageHandlerPropertiesObj;
public void setMessageHandlerProperties(List<Map<String,String>> messageHandlerPropertiesObj) {
if (messageHandlerPropertiesObj == null) {
System.out.println("[MessageHandlerChain] setMessageHandlerProperties() can't be given a null value.");
return;
this.messageHandlerPropertiesObj = messageHandlerPropertiesObj;
@PrePersist
* This method is invoked by the persistence provider prior to every persist operation.
* This is needed because we need to convert, serialize, our <code>@Transient</code> annotated objects into <code>byte[]</code> streams
* so that they can be written into the database.
public void prePersist() {
System.out.println("[MessageHandlerChain] prePersist()");
if (messageHandlerPropertiesObj != null)
messageHandlerProperties = BlobConverter.objectToBytes(messageHandlerPropertiesObj);
if (messageHandlersObj != null)
messageHandlers = BlobConverter.objectToBytes(messageHandlersObj);
@PostLoad
* This method is invoked by the persistence provider after every load operation.
* This is needed because we need to convert, deserialize, <code>byte[]</code> streams back to our <code>@Transient</code> annotated objects.
public void postLoad() {
System.out.println("[MessageHandlerChain] postLoad()");
try {
if (messageHandlerProperties != null)
messageHandlerPropertiesObj = (List<Map<String,String>>)BlobConverter.bytesToObject(messageHandlerProperties);
if (messageHandlers != null)
messageHandlersObj = (List<String>)BlobConverter.bytesToObject(messageHandlers);
} catch (ClassCastException e) {
System.out.println("[MessageHandlerChain] postLoad() Class Cast Exception: "+e);
public String toString() {
return "[MessageHandlerChain] messageHandlerChainID="+getMessageHandlerChainID()+", messageHandlers="+getMessageHandlers()+", messageHandlerProperties="+getMessageHandlerProperties();
The helper class
* <code>BlobConverter</code> is a simple helper class to encode and decode classes as byte[] so that they can be stored into persistent storage.
* @author Samuli Piela
public class BlobConverter {
public static byte[] objectToBytes(Object o) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(baos);
oos.writeObject(o);
return baos.toByteArray();
} catch (InvalidClassException e) {
System.out.println("objectToBytes("+o+"): Invalid Class: "+e);
} catch (NotSerializableException e) {
System.out.println("objectToByte("+o+"): Object not serializable: "+e);
} catch (Exception e) {
System.out.println("objectToBytes("+o+"): Exception: "+e);
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
System.out.println("objectToBytes(): Stream could not be closed: "+e);
if (baos != null) {
try {
baos.close();
} catch (IOException e) {
System.out.println("objectToBytes(): Stream could not be closed: "+e);
oos = null;
baos = null;
return null;
public static Object bytesToObject(byte[] byteArray) {
ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(bais);
Object o = ois.readObject();
return o;
} catch (ClassNotFoundException e) {
System.out.println("bytesToObject(): Class not found: "+e);
} catch (InvalidClassException e) {
System.out.println("bytesToObject(): Invalid Class: "+e);
} catch (IOException e) {
System.out.println("bytesToObject(): IOException: "+e);
} catch (Exception e) {
System.out.println("bytesToObject(): Exception: "+e);
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
System.out.println("bytesToObject(): Stream could not be closed: "+e);
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
System.out.println("bytesToObject(): Stream could not be closed: "+e);
ois = null;
bais = null;
return null;
}anyone?
-
have verizon mifi modem, and downloading a big size game is taking way to long, is there a fast!!!! Way! to download?
hey! thanks! soonermock!
i thought that was a possibility but was'nt sure how that would work through a pc,
i have 2 options and one easier than the other, one would be through a DELL microsoft/windows the other a APPLE desk top,
iill give it a try, thanks again -
Is there an easier way of doing this?
I have a folder of files that include .cr2, .xmp, and .dng extentions. I want to move the .cr2 and .xmp files into a subfolder within the folder. I have a workflow that works as a Finder plug-in, but it seems kind of cumbersome:
Get Selected Finder Items
Get Folder Contents
Filter Finder Items>extention=cr2
Move Finder Items
Get Selected Finder Items
Get Folder Contents
Filter Finder Items>extention=dng
Move Finder Items
Sorry to ask such a basic question, but this is my first attempt at using Automator (well version 2 of first attempt: version 1 moved ALL of the RAW files on my hard drive!). Thanks.Okay, I think I get the gist of it now. The short answer is no, Automator must be told explicitly where to move a file, either in the workflow itself or through user interaction at runtime. The long answer is that if you feed Automator a little code, its intelligence increases dramatically. Here's a workflow I tested successfully:
1. Get Folder Contents -- This is the folder that's already been passed to the workflow by the Finder plug-in.
2. Filter Finder Items -- This gets a list of files that we actually want to move (the result of any action that is a list of files or folders will do, just so long as it doesn't include the destination folder!).
3. Run AppleScript -- This action is found under the Library entry for Automator itself. When you drag the action into your workflow, replace the default code with this:
click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">on run {input, parameters}
-- The nested folder to look for or create:
set folder_name to "RAW"
tell application "Finder"
-- Store the path to the folder we're moving files from:
set folder_A to the container of input's first item as Unicode text
-- Store the path to the folder we want to move the files to:
set folder_B to folder_A & folder_name
-- See if the destination path actually exists, if it doesn't, create it:
if not (folder_B exists) then make new folder at folder_A with properties {name:folder_name}
-- Move the files to the destination path:
move input to folder_B
end tell
end run</pre>I put notes in the code that explain what each line does. Let us know if it works for you.
PowerMac G5 (June 2004) 2x1.8GHz 1.25GB, PowerBook G4 (12-inch DVI) 1x1GHz 768MB Mac OS X (10.4.4) -
ASH
T2
T3
T6
T8
T12
T14
T15
T18
T19
T22
T29
T32
T35
T39
T49
T52
T2
100
68
53
65
74
52
61
63
50
55
53
52
86
45
48
69
T3
0.6
100
51
65
55
49
55
62
34
43
69
55
52
53
58
73
T6
0.6
0.3
100
68
83
74
63
60
65
32
55
62
66
76
63
71
T8
2.6
0.2
3.9
100
58
62
56
68
63
58
60
63
63
73
69
67
T12
1.2
1.9
2.2
6.9
100
86
61
73
47
47
53
67
60
47
58
88
T14
0.2
0.8
3.1
3.4
2.3
100
62
64
38
60
60
56
51
37
56
74
T15
2
0.6
2.6
2.4
0.3
9.5
100
59
57
40
57
60
67
71
57
53
T18
2.1
0.3
2.2
5.1
3.8
3
1.6
100
71
68
50
31
70
63
55
58
T19
1.2
1.6
3
0.2
0.5
3.2
3.2
2.3
100
60
56
65
48
47
58
56
T22
1.2
0.6
3.2
4.7
2.5
3.5
6.5
5.1
2.3
100
61
55
59
60
50
62
T29
3.3
4
1.6
3
1.2
4.7
3.7
3.4
3.5
6.3
100
53
51
67
47
68
T32
0.1
1.3
4.4
2.4
2.8
2.9
3.7
0.2
0.5
3.1
0.4
100
56
74
45
65
T35
4
3.8
0.3
2.9
0.9
3.1
1.8
0.2
0.3
3.5
5.7
0.8
100
62
68
68
T39
0.4
0.7
1.9
1
1.5
3
0.4
0.3
0.3
1.5
0.3
1.6
1.8
100
70Hi Ken
Use Conditional Format to provide a Cell colour fill or a font colour if the Cell contents exceed a certain value.
Here is a thread where the question was to highlight values below a certain value, but I think you will get the idea!
https://discussions.apple.com/thread/5187841?tstart=0
Regards,
Ian. -
Is it possible to copy a DVD into iTunes and then upload it to my iPad? Is there any way of doing this?
Sure, just use Handbrake to encode the DVD movie into a format that is playable on iTunes and on your iPad:
http://handbrake.fr/downloads.php
Once the encoding is complete, move the movie file from your desktop into iTunes and then sync your iPad. Presto, the movie is on your iPad! -
i am a final cut pro user and i recently started using adobe premiere pro. for anyone firmiliar with fcp, there are interesting ways of doing introductions on it and im wondering if anyone could tell me if premiere pro has preset introductions i can use.
Singenu wrote:
I tought about looking in Monitor Activity to see what happens...
Well, when I start working (should I say try to work with FCPX, activity monitor in the %processor column for FCPX jumps rapidly over 100% and reaches more than 200% ??? What the **** is that ?
200% or more is not strange. Remember that your mac has 4 cores (you say it's 3 months old, so I assume it is a new model), so 200% amounts to using 2 of these 4 cores to the max.
Regarding the question of creating a new admin user: while it sits in the same system, it may help if the problem is caused by some user-specific preferences or settings. Not likely in your case, since you seem to have reinstalled from scratch, but still it is worth a try. It takes 5 minutes and may help pinpoint the problem. -
Hello there-
Our Xerox rep helped us set up Airprint to our copier machine. We have department codes set up on our copier so when any one goes to copy or print something they need to punch their code in. Airprint will not work because we have those codes (something prints out to the copier saying error due to accounting codes being set up). Does anyone know if there is a way to override this on our ipads? Thank you!!Hi Nico,
if you want a local test/development setup of Oracle why don't you just install Oracle 11gR2 XE (http://www.oracle.com/technetwork/products/express-edition/downloads/index.html) ?
If you install this you get a database, APEX (4.1), client etc all in one install, this includes a webserver (EPG) on port 8080 without having to configure anything. It's a simple next-next-next installation without much configuration.
If you would like to seperate database and software you can always do this later when you understand the concepts of database/control files etc.
If you would like to upgrade to APEX 4.2 you can download this afterwards and easily install this by running two scripts in SQL*Plus ( apexins.sql and apxldimg.sql ), just check the apex 4.2 installtion guid section EPG for this.
Regards
Bas
b.t.w. If you're running windows 7 - 64 bits just use the 32 bits XE for windows, might get some warnings but you should be able to install and run, good enough for test/dev
Maybe you are looking for
-
Free goods- Sales Order Quota for a customer
Dear Experts I want to restrict the Quota of an free SKU ( Material) to a specific customer. For Eg:-- If a Distributor limit is set for a Consumer Offer as 100 CS. Once the 100 CS is exceeded, System must stop further orders of the item on the Same
-
Links work in iWeb, but not from browser when published
http://web.me.com/mocote All's well since August. Then yesterday, some links decide not to work anymore in browser. Can't create new ones either. What changed? In iWeb, all links look fine in the Inspector. You can click on all external links and fil
-
when watching older tv programing my tv screen does not fill up! where is the aspect ajustment? roku & netgear have them my tv screen fills up using them!
-
Cant open youtube in any browser in macbook pro
Hi. I have a macbook pro from 2010, I am still using snow leopard (10.6.8). It was always hard to play youtube videos on Safari but I was able to get it work smoothly on Chrome. Then starting 2-3 weeks ago I cant open youtube site in any browser at a
-
Camera for macbook pro not detecting camera since upgrade to mountain lion
I recently upgraded from Snow leopard to Mountain Lion and I was trying to make a video call in skype. The camera worked for a minute or so then stopped working. Since then my camera hasn't been detected by my Macbook pro. Can anyone help me?